Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

1

You could just make a player manually save by pressing a save button.

0

No, that's no good.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.