From 8e0caa07693e1bfb0714e16ee2ab9d00ded8c0f7 Mon Sep 17 00:00:00 2001 From: DoomIsEternal <65947351+DoomIsEternal@users.noreply.github.com> Date: Sat, 16 Mar 2024 11:11:42 +0200 Subject: [PATCH] Fix table deep clone --- src/Modules/Table.luau | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Modules/Table.luau b/src/Modules/Table.luau index fdc77a2..0406043 100644 --- a/src/Modules/Table.luau +++ b/src/Modules/Table.luau @@ -1,12 +1,17 @@ return { DeepClone = function(Table: {[any]: any}): {[any]: any} - local function Clone(Source: {[any]: any}) - local Result = {} - for Index, Value in Source do - if type(Value) == "table" then - Result[Index] = Clone(Value) + local Clones = {} + local function Clone(Original) + local Result = Original + if type(Original) == "table" then + if Clones[Original] then + Result = Clones[Original] else - Result[Index] = Value + Result = {} + Clones[Original] = Result + for Key, Value in Original do + Result[Clone(Key)] = Clone(Value) + end end end