PlayerRemoving won't be fired when the script stops due to an error

I save the player’s data when this player leaves the game, using PlayerRemoving.
However, if the script stops (game crashes) due to any bug on it, PlayerRemoving won’t be fired.
Thus, no player’s data will be saved.
Is that supposed to be this way?

It was an exclusive problem in Studio, because I used the “On Unhandled Exceptions” option to stop the script in debugging mode, in case an error occurs.
Disabling this option, then even with the script errors, the script is not interrupted, so PlayerRemoving is running correctly.

A specific way to counteract this issue is using this API:

Conditionally, you need to work with a “cache” which contains the keys of players who were in the last game session and then their respective data. While your game is shutting down/crashing(no idea if it will work), save all the existing data in cache. Clear the cache after PlayerRemoving from the key to avoid unexpected data alternation.

1 Like