I'm saving a table in a Data Store but it doesn't load properly. I'm told it's not efficient to save values with a PlayerRemoving event, but I don't think it would jumble the values around.
If I change the value of strength in-game and rejoin, I'd get that changed value in dexterity!
local key = "player-"..player.userId
local savedStats = statsData:GetAsync(key)
if savedStats then
--Format: {lv,xp,str,dex,foc,vit}
level.Value = savedStats[0]
xp.Value = savedStats[1]
strength.Value = savedStats[2]
dexterity.Value = savedStats[3]
focus.Value = savedStats[4]
vitality.Value = savedStats[5]
else
local statsToSave = {level.Value, xp.Value, strength.Value, dexterity.Value, focus.Value, vitality.Value}
statsData:SetAsync(key, statsToSave)
end
end)
function saveStats(player)
local key = "player-"..player.userId
local statsToSave = {level.Value, xp.Value, strength.Value, dexterity.Value, focus.Value, vitality.Value}
statsData:SetAsync(key, statsToSave)
end
game.Players.PlayerRemoving:connect(saveStats)
