Hi. I’m simply wondering how to correctly put in a new value into a DataStore without messing up other old values. I tried the method I thought worked, but it erased my other value. I am simply using the recommended DataStore code from documentation as shown:
local function setupPlayerData(player)
local playerUserId = "Player_" .. player.UserId
local data
local success, err = pcall(function()
data = playerData:GetAsync(playerUserId)
end)
if success then
if data then
-- Data exists for this player
sessionData[playerUserId] = data
else
-- Data store is working, but no current data for this player
sessionData[playerUserId] = {Points=0, Wins=0}
end
else
warn("Cannot access data store for player!")
end
updateboard(player)
end
If the points already exists for a player, how do I add wins in with a value of zero without messing with the points value? Since data is available for the player (because points exist for them), how do I add new wins data with a value of zero?
I just want to make sure I do it correctly.