Events to use for checking when the script is destroyed

With a script.Destroying:connect() event in a script, if any parent or ancestor of the script is destroyed, the event won’t fire. But this can be fixed by changing the event to be for the script’s parent/ancestor that is destroyed (ex: Character.Destroying:connect() instead)

However, if the player leaves, the Character.Destroying:connect() event will not be fired fast enough for the script to receive the event before it is destroyed. Same thing happens with a PlayerRemoved event by the same script inside the character.

Is there any workaround to this to make sure that the script within a player’s character can execute something when the character is destroyed from the player leaving?

You could use an external controller that isn’t a child of a player to handle these events, that way it won’t be affected when players leave. It’ll be messy but might work.

That definitely works and it might be what I have to resort to, but the script that I am using is in a tool, so I would rather not do that if possible.

“The CharacterRemoving event fires right before a player’s character is removed, such as when the player is respawning.” Player | Roblox Creator Documentation

1 Like