Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Player and Values in him get removed before I can save them?

Asked by 8 years ago
Edited 8 years ago

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! ;)

1function 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
9end
1game.Players.PlayerRemoving:connect(function(Player)--On Player removing
2    SaveData(Player)
3end)
1
You could just make a player manually save by pressing a save button. KordGamer 155 — 8y
0
No, that's no good. Dolphinous 36 — 8y

1 answer

Log in to vote
1
Answered by
k3du53 162
8 years ago
Edited 8 years ago

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.

01function 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
09end
10 
11game.Players.PlayerRemoving:connect(function(Player)
12    SaveData(Player, Player.PlayerValues.Animation.Value)
13end)

If this worked, please accept my answer, as this helps both of us.

Ad

Answer this question