I wanted to make a DataStore script that saves values when the player leave, but the problem is when they leave, their leaderstats is gone. Sometimes it works, sometimes it don't.
game.Players.PlayerRemoving:Connect(function(plr) local key = 'id-' ..plr.userId local stats = plr.leaderstats -- OVERWRITE THE CURRENT SAVETABLE -- datastore:UpdateAsync(key, function(savetable) if savetable then local newtable = {stats.Money.Value} return newtable end end) end)