local Guns = path.to.guns:GetChildren()
-- GetChildren() returns an array (a type of table) that contains all the children
-- of a parent
local randomGun = Guns[math.random(1,#Guns)]
-- Since it is an array, the index will be a number (Array is index-value).
-- We can use the random number to pick what gun.
Currently having trouble explaining it, but I’ll give some links that might explain it better:
Currently, the only thing these 2 lines do is select a random tool (Assuming this folder is only filled with tools) in the Guns folder of ServerStorage.
Do you want the selected tool to be randomized every time they spawn to be in their backpack?
In order to do that, you’ll need to connect whenever a character spawns to a function which gives you a random tool of this folder.
Put this in serverscriptservice (this is an addon):
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player) -- Whenever a player is added to server..
player.CharacterAdded:Connect(function(character) -- Whenever a character is added/respawns..
local Guns = game:GetService("ServerStorage").Guns:GetChildren()
local randomGun = Guns[math.random(1,#Guns)]:Clone() -- Clone() for multi-use
randomGun.Parent = player.Backpack -- It gets sent to the player's backpack
end)
end)