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

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)
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.

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.

Ad

Answer this question