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

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

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.

local plr = game.Players.LocalPlayer
local ShopTools = plr.Backpack:WaitForChild("BoughtTools"):GetChildren()
for i,v in pairs(ShopTools) do
    local clone = v:Clone()
    clone.Parent = plr.Backpack
end

2 comments

0

You took that wrong, i said that table.foreach is deprecated, not unusable ;p

0

Formatted your code.

1 answer

✓ Accepted answer

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

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

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

2 comments

0

It still doesn't work on servers, but works completely fine on studio.

0

Are you using a localscript?

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