PlayerRemoving event firing when it's not supposed to?

I have been working on a game for a while and recently i’ve began running into an issue I haven’t seen before, whenever I run a playtest, the PlayerRemoving event I have to save player data fires almost immediately, and it’s been causing issues with the datastore for a couple of my testing accounts. I have also tried using the local server play test to try with new players and the issue persists and breaks my datastore entirely for those accounts.

I don’t even know what the issue could be, below I provided a screenshot of the output showing it firing the messages indicating the player has left and the code behind it, anybody know what the issue could be?

game.Players.PlayerRemoving:Connect(function(player) -- For saving data when a player leaves
	local PlayerID = "Player_" .. player.UserId
	print(tostring(player).. " has left")
	saveGame(player, PlayerID)
	saveInventory(player, PlayerID)
end)

image_2024-07-09_133600922

1 Like

What do you mean it’s firing when it’s not meant to? The event is meant to be fired when the player leaves, so of course it would fire the moment they leave the game. Could you please elaborate?

The issue is that it fires as soon as I START the playtest, not even when they leave like it’s supposed to and that’s what’s causing issues.

Alright, in that case I’m not sure of the cause.

Are you testing it on studio? If so, try testing on the actual website. Sometimes the studio’s playerremoving event acts kinda weird.

alright ill give that a try, thanks for the tip