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

How to clone values in a table?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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 :)

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. Seabiscuitz 21 — 7y
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. AstrealDev 728 — 7y
Ad

Answer this question