Table coupling in Luau

local T = {1, 2, 3}
local S = T
S[1] = 4
print(T) --prints out {4, 1, 3}

Expected behavior

It’s supposed to stay as it was since i didn’t change it in any way, or does the S table link to the T table? Wasn’t written anywhere anything about it.
I tried different ways like using table.clone() (somewhy it didnt work the first time), moving it to another module script, changing the variable in module script to a getfunction, freezing the table.

1 Like

its just linking variable to another variable heres same thing but with part in workspace

local baseplate = workspace.Baseplate -- <--- referencing some object
local anotherlinktobaseplate = baseplate -- <--- linking baseplate value to another one
anotherlinktobaseplate = "my name got changed" -- <--- name change
print(baseplate.Name) -- output "my name got changed"

its intended behaviour since S[1] is link to T[1]

Yes it does.
table.clone is what you need.

local T = {1, 2, 3}
local S = table.clone(T)
S[1] = 4
print(T) --> prints {1, 2, 3}

This post belongs in #help-and-feedback:scripting-support

2 Likes

Then why doesnt it work with basic integers and other default types?