My friend wrote a gear randomizer script but it doesn’t work, I’m not a scripter so I cant help him either
He has looked
Here’s the code:
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Folder = RS:WaitForChild("Folder")
local function onCharacterAdded(character)
local Tools = Folder:GetChildren()
local ToolsTable = Tools
local chosenTools = {}
repeat
local selectedIndex = math.random(1, #ToolsTable)
table.insert(chosenTools, ToolsTable[selectedIndex])
table.remove(ToolsTable, selectedIndex)
until #chosenTools >= 1
local plr = Players:GetPlayerFromCharacter(character)
for i,v in pairs(chosenTools) do
Folder:FindFirstChild(v.Name):Clone().Parent = plr.Backpack
end
end
local function onAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onAdded)
That’ll only return 1 as you never ask it to return 3 of those type, unless you mean there’s 3 weapons and it returns one at random. If you’re only returning one however what’s the need for the table?
Hi,
You have the same problem that i had!
So i think i can help you.
local serverStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local Folder = serverStorage:WaitForChild("Folder"):GetChildren()
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local randomGear = Folder[math.random(1,#Folder)]
randomGear.Parent = player.Backpack
randomGear.Parent = character --this will make tool equip automatically
end)
end)