Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This simple tool script won't work?

Asked by 9 years ago

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?

0
You may want to change the "i" in the second loop to something else. RedCombee 585 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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 is to j (or anything else you'd like) and it should work.

0
Didn't work. :( Protoduction 216 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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

Answer this question