Humanoid.Died Event Fires Twice, and then Stops Working

Hello everyone. I am trying to rework the respawn system for my game, and it works well the first time you reset (Humanoid.Died fires, and enables the GUI), but after dying a second time, it respawns the player, but the GUI doesn’t show.
I know this isn’t a problem with a GUI, because I put a print statement everytime that Humanoid.Died is fired, and it doesn’t fire the second time that the Player dies.

The code responsible for detecting the event is

local event = game.ReplicatedStorage.Play
local plr = game.Players.LocalPlayer
local PlayGui = script.Parent
PlayGui.Enabled = true
local PlayGui = script.Parent
local player = game.Players.LocalPlayer
player.Character:WaitForChild("Humanoid").Died:Connect(function()
	
	PlayGui.YouEarned.Transparency = 0
	PlayGui.YouEarned.Text = "You earned "..math.round(player.leaderstats.Score.Value/250).." Gold Coins"
	--	player.leaderstats.GoldCoins.Value += math.round(player.leaderstats.Score.Value/250)
	PlayGui.TextLabel.Text = "You died!"
	PlayGui.Play.Text = "Continue"
	PlayGui.Enabled = true

	PlayGui.Play.MouseButton1Up:Wait()
	PlayGui.YouEarned.Transparency = 1
	wait(0.1)
	PlayGui.TextLabel.Text = "Wilderness Survival"
	PlayGui.Play.Text = "Play"


end)

It is a local script, by the way.
Any help is appreciated, I’ve been stuck on this for the past five hours!

Have you tried to do print statements for when the humanoid died? Maybe it could be the GUI not registering it or updating? No clue. Normally that connect function should work.
if anything you can set a variable to the character by doing

local character = player.Character or player.CharacterAdded:Wait()

Are there any errors in the output?

None that are related to the script.

When you die, the humanoid you’re referencing no longer exists, therefore .Died never fires. Place it under a
.CharacterAdded:Connect()
and it should keep firing!

1 Like

I tried doing the print statement, it prints for the first time that the humanoid dies, but it doesn’t for the second time, so the GUI is probably fine.

Are you saying something like this?

local event = game.ReplicatedStorage.Play
local plr = game.Players.LocalPlayer
local PlayGui = script.Parent
PlayGui.Enabled = true
local PlayGui = script.Parent
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function()
	player.Character:WaitForChild("Humanoid").Died:Connect(function()
		print("player Died")
		PlayGui.YouEarned.Transparency = 0
		PlayGui.YouEarned.Text = "You earned "..math.round(player.leaderstats.Score.Value/250).." Gold Coins"
		--	player.leaderstats.GoldCoins.Value += math.round(player.leaderstats.Score.Value/250)
		PlayGui.TextLabel.Text = "You died!"
		PlayGui.Play.Text = "Continue"
		PlayGui.Enabled = true

		PlayGui.Play.MouseButton1Up:Wait()
		PlayGui.YouEarned.Transparency = 1
		wait(0.1)
		PlayGui.TextLabel.Text = "Wilderness Survival"
		PlayGui.Play.Text = "Play"


	end)
end)
1 Like

Put this script in StarterCharacterScripts
Or

local character = player.CharacterAdded:Wait()
1 Like

.CharacterAdded already passes the player’s character:

player.CharacterAdded:Connect(function(character) ...

but yeah, that’s about right

It’s in starterGui, which works too, I think.

In StarterCharacterScripts it will reset every time so, just do it

1 Like

^^honestly this might be the cleaner solution for local scripts

1 Like

It doesn’t seem to work. Now, the GUI doesn’t get enabled on the first reset, and it doesn’t print anything either…

1 Like

Put this in your code, it will fix it.

local character = player.CharacterAdded:Wait()

the CharacterAdded event doesn’t (usually) fire on the first time the script is run.
add the humanoid.Died event on top of it too.

Doesn’t it run on the server Only? Im not sure tho.

Thank you, it works now! Thanks everyone for helping me.