CharacterRemoving not FIring Under StarterCharacter

Why does CharacterRemoving not fire when under the character object but does when under the player instance? I printed the player and character fine, but the event just doesn’t fire.

my code. script is under starter character container

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

player.CharacterRemoving:Connect(function(character)
	print('hello')
end)

Is this in a localscript?: Maybe it is

Put the (local)script in the StarterPlayerScripts.
The script gets deleted when the character respawns.

Note that the .CharacterRemoving only fires when the player’s Character changes(?)

1 Like

its a local script so your saying the script deletes too fast before the event can fire?

Basically what @DiscoDino01 is saying is that .CharacterRemoving fires right before your Character gets deleted. It doesn’t allow any time for the script to recieve the event and act on it because the Character is deleted instantly after the event is fired. Put that script in StarterPlayerScripts so that it is not removed when the Character gets deleted.

Look at the example usage on this documentation page

1 Like

so it happens in this order character dies → character’s children get deleted → event fires → character instance is deleted?

and another thing, with events connected on a local scripts in starter character, do i gotta worry about disconnecting events since if the script is getting deleted? or i gotta disconnect the events even if the script gets delete? or does garbage collector automatically delete connections if the script is deleted?

1 Like

character death → despawn timer started → despawn started → event fires → (no delay) character deleted

if the script is under the character it gets deleted as soon as the event is fired so the script cant process the event


whenever an instance is destroyed (parent was destroyed therefore instance destroyed, or just itself is destroyed) all connections to events that instance has will be disconnected automatically

1 Like

This is better than any explanation I could give.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.