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

How to clone values in a table?

Is it possible to clone values in a table at all? I tried simply using the :Clone() function, but it doesnt seem to support table values. So, does anyone happen to know a function with the capabilities of cloning values in a table? This is the table below in my script. Help is greatly appreciated! :)

local plr = game.Players.LocalPlayer local ShopTools = plr.Backpack:WaitForChild("BoughtTools"):GetChildren():Clone() table.foreach(ShopTools, function(i, v) v.Parent = plr.Backpack end)

1 answer

✓ Accepted answer

I think I understand what you want. I may be wrong, please let me know if I am.

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

This will put any tools the player has inside of "BoughtTools" into the player's backpack.

for i,v in pairs() - This is a for loop that goes through a table you give it. i is the index, and v is the item it's on. I used the loop to go through every item, clone it, and set the clone's parent as the player's backpack.

Hope I helped. Let me know if I did :)

2 comments

0

Yes this did help! The only problem is that the loop only runs on studio, but when its published and played on Roblox's server, it just breaks the script.

0

Welp, that's another problem! You'll have to post that as another question and provide some more info! Glad to hear I helped. Be sure to accept my answer if you think it's worthy.

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