I'm using the PlayerRemoving Event to save Values in a player inside a DataStore, but the Player and the Values get removed so fast, that I can't even read them to save them. Thanks for any help! ;)
function SaveData(Player) local Key = tostring("Player-"..Player.userId) local Success, message = pcall(function() AnimationDataStore:SetAsync(Key,Player.PlayerValues.Animation.Value) end) if not Success then print("An error occurred: " .. message) end end
game.Players.PlayerRemoving:connect(function(Player)--On Player removing SaveData(Player) end)
Although I'm not very good with this, I'll give a go at helping you out. Maybe if you save the stats in a variable before the player is gone.
Ex.
function SaveData(Player, stat) local Key = tostring("Player-"..Player.userId) local Success, message = pcall(function() AnimationDataStore:SetAsync(Key, stat) end) if not Success then print("An error occurred: " .. message) end end game.Players.PlayerRemoving:connect(function(Player) SaveData(Player, Player.PlayerValues.Animation.Value) end)
If this worked, please accept my answer, as this helps both of us.