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

What is the easiest way to "clone" a table?

Asked by 10 years ago

Let's say I had table A:

local A = {1,2,3,4,5}

and I want to assign that table to a variable so I can edit it:

local B = A

But whenever I do something to "B", Table "A" gets changed as well. I know why, but what I'm asking is how would I "clone" this table, so that I could edit it without changing the original table?

NOTE: I've used a for loop to insert values from Table A into B, but the for loop becomes useless if I have more table within tables or tables with indexes.

1 answer

Log in to vote
1
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

The Wiki has an article for this:

http://wiki.roblox.com/index.php/Cloning_tables

Ad

Answer this question