Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

This simple tool script won't work?

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?

1 comment

0

You may want to change the "i" in the second loop to something else.

2 answers

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.

1 comment

0

Didn't 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

This discussion is preserved as it was. New answers, comments, and votes are closed.