How to add new data without affecting old data

If a player has a table saved and then later on in an update I need to add a new value to that table but everytime they join it loads their data so I cant change it how could I add it without resetting/changing their data?

Pretty much I have this two arrays that save what the player has unlock/hasnt but the IndexLocked array is only assigned when the player is joining for the first time. So if I add another value to the locked array only players who do not already have data will have the new value in their array.

I hope this makes sense.

local IndexLocked = {"Common", "Uncommon", "Rare", "Epic", "Legendary", "Mythic", "Azure", "PhantomFire", "Crimson", "Azure:Cyclone", "Crimson:Demon"}
	local IndexUnlocked = {}

When the player joins, you could check both IndexLocked and IndexUnlocked and see if the lists are missing something from your newest list. Then simply update IndexLocked to include the ones that are missing. Here is an example:

local CompleteList = {"Common", "Uncommon", "Rare", "Epic", "Legendary", "Mythic", "Azure", "PhantomFire", "Crimson", "Azure:Cyclone", "Crimson:Demon"}
local IndexLocked = {"Uncommon", "Rare", "Epic"}
local IndexUnlocked = {"Common"}
for index, value in CompleteList do
    local found = table.find(IndexLocked, value) ~= nil or table.find(IndexUnlocked, value) ~= nil
    if found == false then
        table.insert(IndexLocked, value)
    end
end
-- Save updated indexLocked
1 Like

I think I may not completely understand your post.

I’m assuming your IndexLocked array is a reference table which you assign to each player, but because of table references, when you insert it for one player it’s replicated for all others?

If so, you could just clone it. To do a shallow copy simply use table.clone(IndexLocked), but if you need a deep copy - e.g. in the case of nested tables - you would need to use something like this

Sorry I should have elaborated, this is in a script that saves data for each player and these arrays are just setting the data for a player who has no data. Once a player leaves after joining for the first time it saves each array for what they have/havent unlocked.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.