Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to prevent scripts from breaking after you die?

Asked by 5 years ago

I do have a mini-function I made that fires when the player dies, but it only runs once and stops after that.

game.Players.LocalPlayer.Character.Humanoid.Died:connect(function()
print("You have died!")
end)

Is there a way to make something like this continue?

0
Do you want this to be on a local script or a regular one? Le_Teapots 913 — 5y
0
I mean, if i wanted this to be on a regular script then i wouldn't have used the "LocalPlayer" thing lol RedWirePlatinum 53 — 5y

1 answer

Log in to vote
2
Answered by
Asceylos 562 Moderation Voter
5 years ago
Edited 5 years ago

Yeah.

Put the following LocalScript into StarterPlayerScripts:

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
    char:WaitForChild("Humanoid").Died:Wait()
    print'You have died!'
end)

The issue with your script is that the Character your script is referring to gets removed when the player dies.

1
Alternatively, using StarterCharacterScripts could be a better option. Since the scripts get destroyed and re-run when you respawn. Depends on your use case.   Psudar 882 — 5y
1
Now I'm just getting an error saying "Humanoid is not a valid member of model" RedWirePlatinum 53 — 5y
0
I am sorry, please use the updated version of the script. Asceylos 562 — 5y
0
it worked, thank you! RedWirePlatinum 53 — 5y
Ad

Answer this question