Should I disconnect local events pertaining to the character on player death?

I am making my game handle a players death properly. Before, I had everything stored in PlayerScripts, which meant the character would break permanently if the player died. Now, I’ve modified the code to go in CharacterScripts, so it will reset on death.

I am not disconnecting any events when this happens, and on respawn, certain aspects of the new character script are acting unusually. ( Event related code. )

Do I need to be disconnecting these when the player dies? Will these events stack? Or get cleaned up when the model is reloaded.

I am using LoadCharacter to respawn the player on Humanoid:Died() if that makes a difference.

For some reason when you respawn and such the character is not destroyed, but just parented to nil.

What I do to guarantee disconnections is

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    player.CharacterRemoving:Connect(game.Destroy)
end)

So that when their character is being removed it will be destroyed rather than just parented to nil. This might be redundant but it is good to guarantee things.

1 Like

Did you mean to say:

player.CharacterRemoving:Connect(function(character)
    character:Destroy()
end)

?

Same thing.

No I did not. a:b() is the same as a.b(a) so it is called as game.Destroy(character) which destroys the character.

It doesn’t. But as I said, there is a difference between . and :

Unneeded;

local t = { x = 5 }

function t:f()
    print(self.x)
end

t:f() -- 5
t.f(t) -- 5
t.f() -- attempt to index a nil value

If you want a further explanation feel free to DM me

just tested it and it works but I find the other way more readable imo.