and I would like to change the value in Players > 123456 > Value2 to false. How would I do this? I have this function that doesnt work:
module.update = function(newData)
--Reference the table above
local read = module.read()
local function check(tempList)
for valname,oldVal in tempList do
if not newData[valname] then continue end
if not tempList[valname] then tempList[valname] = newData[valname] continue end
if typeof(oldVal) == "table" then
tempList[valname] = check(tempList[valname])
else
tempList[valname] = newData[valname]
end
end
return tempList
end
check(read)
return read
end
And to update it I would like to do this with the update function:
module.update({
["123456"] = {
-- Doesn't effect any values except these under 123456
["Value1"] = 1856
["Value2"] = false
}
})
Thanks! If I left out anything or need more info, just send a reply!
I don’t have time to test this right this second but maybe something like this?
function update(changes, previous)
previous = previous or Players
for k, v in pairs(changes) do
if previous[k] ~= nil then
if type(v) == "table" then
update(changes[k], previous[k])
else
previous[k] = v
end
end
end
end
-- ALL UNDER UPDATE FUNCTION
local read = module.read()
local function update(changes, previous)
for k, v in pairs(changes) do
if previous[k] ~= nil then
if type(v) == "table" then
update(changes[k], previous[k])
else
previous[k] = v
end
end
end
end
update(newData, read)
print(`changed value:`, read)