I have a function that goes through a table recursively to find a key, then changes the key's value. However, despite the function running without error, and the print statements in the middle printing what I expect, the values within the original table aren't changed. I feel like the values the script is altering aren't the actual values from the original table.
function dataManager.setStat(player, statName, newValue)
local statFound = false
local function recursiveIteration(curTable)
for key,value in pairs(curTable) do
if key == statName then
print(key , " = " , value)
statFound = true
value = newValue
print(key , " = " , value)
elseif type(value) == "table" then
recursiveIteration(value)
end
end
end
waitForSessionStats(player)
recursiveIteration(sessionStats[getScope(player)])
return statFound
end
I get the output
statName = oldValue
statName = newValue
But the original table's values don't change.
