Humanoid.Died not working the second time around

Hi, as you may know tools delete from the backpack after a character dies, so I’m trying to make it so that when the character dies, the tools get parented to a folder for that character so then when they respawn the tools can be parented to the backpack. But I’m trying to use humanoid.Died, and it only works the first time around and not the second time. Does anyone know why?

code:
image

1 Like

where is the script, this is what i think is happening;

When the character is defined upon joining, it looks at that character, after the character dies, The script is still refering to the character that is now dead, which is now nil but i’m not completley sure, can you add a

print(character)

into the script, then play the script, then kill the character as you’d usually test it, and see if the character is returned as nil

1 Like

it is in starterplayerscripts would this matter where it is on the character?

Okay, that’s the problem. when the character dies, the script isn’t reloaded, so it doesn’t define the character again, i remember a solution i made a while ago give me a sec

2 Likes

Actually i just moved the script’s location, will this be an issue for your script or will it work fine anyway? you can put it into startercharacterscripts instead in which the script will spawn again along with the character, defining it again

no the location shouldnt matter

You just have reset the “died” event to the new character that is assigned to the player after the old character object is removed.

Use the Player | Roblox Creator Documentation event to get the new character.

I already tried that based on another post but it didnt work

Okay, try putting it into the StarterCharacterScripts folder and see how it works

1 Like

Ok yeah it works and the humanoid.Died works now, but the second part of the code doesn’t

player.CharacterAdded:Connect(function(newCharacter)
    --Give back tools routine

    newCharacter:WaitForChild("Humanoid").Died:Connect(function()
        --death routine
    end)
end)
2 Likes

image
this part?

1 Like

What i think might be happening is the script is resetting before it gets to that part

Did you change the time it takes for characters to respawn, it takes 5 seconds by default and you’re making it wait 5.1

Players.RespawnTime (roblox.com)

No i did that so that when the tools get parented back to backpack, it would wait .1 seconds so it wouldn’t deleted immediately

I just tried player.CharacterAdded, but it didnt work

Trust me I do this in my own game. The exact same thing you are doing (accept I don’t save the tool copies I just give them a new one). The concept is the same. After a player’s character dies. You give the new character assigned to the player the set of tools back or a new set.

the script resets with the character because it’s in startercharacterscripts, which prevents the script from finishing

Because of this, you are actually better off putting it in starterplayerscripts and doing what emskipo said

(This does work.)

Ok so i did what @Emskipo said, and it doesnt work the first time but it does work the second time.

could i just kill the character when he joins then give them tools so the first time could be over with?

define the character before the function then run it,

what do you mean by defining the character?