Saving tables with null values within

When saving a table, it seems that SetAsync ignores whatever comes after a null value. For instance, lets say I have a table for unlocked maps, UM[USERID] ={} in which, during playtime, the player has unlocked maps 1 and 4 so … UM[xxx][1] and UM[xxx][4] are true … but 2 and 3 were never unlocked (nil) therefore when I save game and reload only UM[xxx][1] is true… all the rest is ignored…
The solution I found is to run a “for do” previous to save to change “nil” for “false” for each map but I wonder if there is a better solution.

There is really no other solution for trying to save a null value inside of a table since null values are used to remove values. Just use a boolean, empty table, or whatever you wanted “null” to be when saving to the Datastore or any other place.

Can I see the script that loads and reads the data from the datastore? Because it should save UM[xxx][4] too and the problem may be in you implementation.

I´m sorry for late reply. see script below. REG is UserId
local MEUSDADOS_V01 = game:GetService(“DataStoreService”):GetDataStore(“DADOSPESSOAIS”, “Ver01”)
MEUSAVEGAME[REG] = MEUSDADOS_V01:GetAsync(REG) or nil
local ii = 1
_G.MOEDAS[REG] = MEUSAVEGAME[REG][ii] ii = ii + 1
_G.ACERTOS[REG] = MEUSAVEGAME[REG][ii] ii = ii + 1
_G.DERROTADOS[REG] = MEUSAVEGAME[REG][ii] ii = ii + 1
_G.DESTRAVAMAPA[REG] = MEUSAVEGAME[REG][ii] ii = ii + 1
… and so on …

BTW … forgot to mention that there is a “if then” that will only run if it finds the MEUSAVEGAME[REG] … otherwise it runs lines for starting values (like amount of coins and stuff like that)

Hi. Yeah, I was afraid of that, but thanks for the help anyway.