A table isn't an instance that you can just call :Clone() on.
If you want to clone a table, do this:
local first_table = {5, 15, 20, 25, 30}
local second_table = {}
for i = 1, #first_table do
second_table[i] = first_table[i]
end
Now, second_table has all of the values in first_table.
And if you want to put each of their values into a player's inventory, you need to iterate through the table again.
for i = 1, #second_table do
second_table[i].Parent = player.Backpack
end
I know that second_table contains only numbers, but the same thing can be done with a table that contains tools.
Also, with tables, you can't just do this to clone tables:
test_table_1 = {5, 10, 15, 20, 25, 30}
test_table_2 = test_table_1
What that does is simply creates another variable for the exact same table in memory. You're not cloning the first table, you're just creating another reference for it.
test_table_1[1] = 5
test_table_2[1] = 10
Since test_table_1 and test_table_2 are referencing the same table in memory, both of these lines are modifying the same index of the same table.
print(test_table_1[1])
print(test_table_2[1])
Since we changed the first index of the same table to 10 on the last line, and both variables reference the same single table in memory, both of these lines produce the same result.
1 comment
Thank you, good explanation.