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

PlayerRemoving not being run in studio or in-game?

Hi all,

I'm trying to save my datastore and it was working fine but I've renamed some variables and for some reason can't get the function to run in-game or in studio. I've placed prints around functions that should be run but console isn't receiving anything. The code is as follows:

game.Players.PlayerRemoving:Connect(function(player)
	local suitSuccess, suitError = pcall(function()
		gamepassDataStore:SetAsync(player.UserId.."-PresidentialSuit", game.Players[player.Name].data.IsSuitEnabled.Value)
	end)
	if suitSuccess then
		print("Suit gamepass has been saved for "..player.Name.. "!")
	else
		print("There was an error saving Suit gamepass for "..player.Name)
		warn(suitError)
	end
	
	local faceSuccess, faceError = pcall(function()
		gamepassDataStore:SetAsync(player.UserId.."-FaceID", game.Players[player.Name].data.FaceID.Value)
	end)
	if faceSuccess then
		print("Face gamepass has been saved for "..player.Name.. "!")
	else
		print("There was an error saving face gamepass for "..player.Name)
		warn(faceError)
	end
	
	local dominusSuccess, dominusError = pcall(function()
		print("1")
		gamepassDataStore:SetAsync(player.UserId.."-Dominus", game.Players[player.Name].data.IsDominusHatEnabled.Value)
		print(game.Players[player.Name].data.IsDominusHatEnabled.Value)
	end)
	if dominusSuccess then
		print("Dominus gamepass has been saved for "..player.Name.. "!")
	else
		print("There was an error saving Dominus gamepass for "..player.Name)
		warn(dominusError)
	end
	
	local sparkleSuccess, sparkleError = pcall(function()
		gamepassDataStore:SetAsync(player.UserId.."-SparkleTime", game.Players[player.Name].data.IsSparkleHatEnabled.Value)
	end)
	if sparkleSuccess then
		print("Sparkle Time gamepass has been saved for "..player.Name.. "!")
	else
		print("There was an error saving Sparkle Time gamepass for "..player.Name)
		warn(sparkleError)
	end

	local dominoSuccess, dominoError = pcall(function()
		gamepassDataStore:SetAsync(player.UserId.."-Domino", game.Players[player.Name].data.IsDominoCrownEnabled.Value)
	end)
	if dominoSuccess then
		print("Domino Crown gamepass has been saved for "..player.Name.. "!")
	else
		print("There was an error saving Domino Crown gamepass for "..player.Name)
		warn(dominoError)
	end
	
end)

The BoolValues, etc aren't null and have values that aren't being saved in the datastore for some reason.

Your help is greatly appreciated.

4 comments

0

If you are actually using roblox gamepasses, you do not need to (and shouldn't) save them. Instead each time player joins you should call UserOwnsGamePassAsync(). That is because player could in theory buy gamepass in the browser (on the game page)

0

Sleazel, the gamepasses offer a toggle which means I need to save whether or not they have them enabled, and that doesn't solve my problem.

0

If you are not getting any output in the console, the problem MUST be somewhere else. It looks like your code is not being run at all. Maybe there is some code before that is caught in infinite loop?

0

If there is Its not printing a yield so I don't think thats the issue..

1 answer

✓ Accepted answer

Player remvoing event doestn reliable fire when last player leaves bc the server shutdowns then

see this article how to properly save

1 comment

0

The issue isn't that it is not being fired, it is, and I tried using the article to reconstruct my saving method and even still, it fires but does not save

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