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

Why is this "for i,v in pairs" script not working on Roblox servers, only in studio?

Asked by 8 years ago
Edited by Shawnyg 8 years ago

So first, i had table.foreach and then someone told me that it was not usable anymore. So i used the for i,vin pairs instead, as most people suggested, but it still doesnt seem to work. Can anyone please tell me what i should do to correct the script? Thanks!

The script is below.

1local plr = game.Players.LocalPlayer
2local ShopTools = plr.Backpack:WaitForChild("BoughtTools"):GetChildren()
3for i,v in pairs(ShopTools) do
4    local clone = v:Clone()
5    clone.Parent = plr.Backpack
6end
0
You took that wrong, i said that table.foreach is deprecated, not unusable ;p RubenKan 3615 — 8y
0
Formatted your code. Shawnyg 4330 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

It is usable, they are wrong. If you want to use an actual loop you should use next over pairs...

1local plr = game.Players.LocalPlayer
2local BoughtTools = plr.Backpack:WaitForChild("BoughtTools"):Clone():GetChildren()
3print("Bought tools loaded...")
4wait(3)
5for _,tool in next, BoughtTools do
6    tool.Parent = plr.Backpack
7end

Tell me if it prints "Bought tools loaded..."

0
It still doesn't work on servers, but works completely fine on studio. Seabiscuitz 21 — 8y
0
Are you using a localscript? cc567 50 — 8y
Ad

Answer this question