I’m making a modulescript for a leaderboard system and, for some reason, a reference variable changes when its reference changes. I have no clue how this is happening because I’m not changing it myself, and it should stay the way it was set to before since I experimented with this segment of code in a different script and it worked as intended, yet it changes no matter what. How can I fix this?
prev = LB
print(prev) --prints the version of the LB I want
local function ClearOut(LB, Scores)
local clear = {}
for spot, key in ipairs(LB) do
if Scores[key].mathplace == 0 then
table.insert(clear, key)
end
end
for i,v in ipairs(clear) do
local pos = table.find(LB, v)
table.remove(LB, pos)
end
end
ClearOut(LB, Scores)
print(prev) --prints the updated LB from ClearOut function, not what I want
This is not what I meant. I meant that I have two variables, and I have set one of those variables to the other. Normally, the variable that has been set to the other does not change when the variable that it is set to changes, it should stay the same. However, in this example, that is not happening, and that’s what I want to fix.
That sounds similar to my problem. The variable in question is changing when the table I have set the variable to changes, which of course isn’t what I want.