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! ;)
1 | function SaveData(Player) |
2 | local Key = tostring ( "Player-" ..Player.userId) |
3 | local Success, message = pcall ( function () |
4 | AnimationDataStore:SetAsync(Key,Player.PlayerValues.Animation.Value) |
5 | end ) |
6 | if not Success then |
7 | print ( "An error occurred: " .. message) |
8 | end |
9 | end |
1 | game.Players.PlayerRemoving:connect( function (Player) --On Player removing |
2 | SaveData(Player) |
3 | 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.
01 | function SaveData(Player, stat) |
02 | local Key = tostring ( "Player-" ..Player.userId) |
03 | local Success, message = pcall ( function () |
04 | AnimationDataStore:SetAsync(Key, stat) |
05 | end ) |
06 | if not Success then |
07 | print ( "An error occurred: " .. message) |
08 | end |
09 | end |
10 |
11 | game.Players.PlayerRemoving:connect( function (Player) |
12 | SaveData(Player, Player.PlayerValues.Animation.Value) |
13 | end ) |
If this worked, please accept my answer, as this helps both of us.