Help plz, random weapon in chest "loot box"

how i can make the loot box "cargo" give the player a random weapon ?
thank you.

You will need a server / default context script that detects when the player interacts with the box (an interactable trigger will work).

You would then need to add your weapon templates to your script and create a table (array) of your weapons. You could add them as custom properties to the script, and then build your table in the script.

For example (untested code, but will give you an idea):

local TRIGGER = script:GetCustomProperty("Trigger"):WaitForObject()

local ASSAULT_TEMPLATE = script:GetCustomProperty("AssaultTemplate")
local PISTOL_TEMPLATE = script:GetCustomProperty("PistolTemplate")
local SMG_TEMPLATE = script:GetCustomProperty("SMGTemplate")

local weapons = {

	ASSAULT_TEMPLATE, PISTOL_TEMPLATE, SMG_TEMPLATE
	
}

local function PlayerInteracted(trigger, other)
	if(Object.IsValid(other) and other:IsA("Player")) then
		local weapon = weapons[math.random(#weapons)]
		
		weapon:Equip(other)
	end
end

TRIGGER.interactedEvent:Connect(PlayerInteracted)

You will likely want to remove the existing weapon if the player has one.

https://docs.coregames.com/api/equipment/

thank you so much for this topic i will try it :relaxed: