Is this how UpdateAsync works?

I have a question about UpdateAsync. Lets say you save this is what is stored in a dataStore:

data = {
    plrs = {'JardIsAPotatoHAH','Jotslo','Gabe'},
    Id = 0000
}

Lets say I just want to update the Id value, Is this the right way too do it?

DataStore:UpdateAsync(player.UserId,function(pastData)
    local data = {
        Id = 0000001
    }

        return data
end)

So would this only update only the Id value?

Yeah, it would only update the Id value in the data store for the player.

So, when you call DataStore:UpdateAsync() with that callback function, it will update only the Id value in the data store for the specified player, and leave the plrs value unchanged.

1 Like

wouldn’t this get rid of the plrs key?

As the data is a table, If you create a new table it would replace the old one.
It works like a Get, Do function, Set

So as you want to keep all the other data unchanged you just need to amend the id and return the amended original table.

-- in update async function body
pastData.Id = 000001 
return pastData

UpdateAsync() – if the value already exists
SetAsync() – if the value does not exist

1 Like

Thanks @ShaShxa and @leterence! I was assuming that using UpdateAsync would well update it and not replace it otherwise it would basically just be SetAsync, Thanks for clarifying!

Sense @ShaShxa replied first all set their thing as solution!

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