Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to prevent scripts from breaking after you die?

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?

2 comments

0

Do you want this to be on a local script or a regular one?

0

I mean, if i wanted this to be on a regular script then i wouldn't have used the "LocalPlayer" thing lol

1 answer

✓ Accepted answer

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.

4 comments

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.  

1

Now I'm just getting an error saying "Humanoid is not a valid member of model"

0

I am sorry, please use the updated version of the script.

0

it worked, thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.