table.clone() isnt actually clone a table fully. For example, if you have tables inside the cloned table, if you change something inside these tables it will replicate on the original table.
Code example:
local Def = {
Table = {
Boolean = false;
};
}
local New = table.clone(Def)
New.Table.Boolean = true
print(Def.Table.Boolean) --it will print true
Is there any way to copy it and that it wont replicate to the original table?
local Def = {
Table = {
Boolean = false;
};
}
local New = Def -- just define a variable as the initial table.
New.Table.Boolean = true
print(Def.Table.Boolean) --it will print true
local function deepCopy(original)
local copy = {}
for k, v in pairs(original) do
if type(v) == "table" then
v = deepCopy(v)
end
copy[k] = v
end
return copy
end
local test = {
lol = true,
moretable = {lol1 = false}
}
local new = deepCopy(test)
new.moretable.lol1 = true
print(new)
print(test)