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)
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.
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?
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