I'm working on a game, and when the match starts, it's meant to give every players the starter weapons.
for i,v in pairs(game.Players:GetChildren()) do for i,c in pairs(game.Lighting.Weapons:GetChildren()) do v:WaitForChild("Backpack") c:clone().Parent = player.Backpack end end
My code doesn't work, it's in a normal script, inside a model in Workspace. Can anybody help?
The problem is that you have your two index variables named i
. That means the second i
is overriding the first. Change either of the two i
s to j
(or anything else you'd like) and it should work.
Try using this. You're not calling player
as it's a nil
value, so you need to use v
. Also, you're using i
twice. You need to change the i
in one of those for loops to something different or the script will not work.
for i,v in pairs(game.Players:GetChildren()) do v:WaitForChild("Backpack") for _,c in pairs(game.Lighting.Weapons:GetChildren()) do local tool = c:Clone() tool.Parent = v.Backpack end end