Why does table.clone not clone the tables inside of it too?

Spent multiple hours trying to find out why a bug existed.

local x = {val = "123", val2 = {x = 0}}
local y = table.clone(x)
print(tostring(x), tostring(y)) --different memory addresses
print(tostring(x.val2), tostring(y.val2)) --despite being cloned, those still have the same address

I feel like very bad things would happen if I didn’t know about this

You may want to check out deep clones:

1 Like

Yeah I realized I need to do something like this, I just wish they could say it doesn’t clone other tables in the description of the function in Studio, since I haven’t checked the documentation about table.clone but just saw it from autocomplete

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.