Humanoid.Died isn't calling for some reason

I want to make a Humanoid.Died event for a minigame I’m making, but Humanoid.Died is not calling. Here is my code:

plr.CharacterAdded:Connect(function(char)
		local h = char:FindFirstChild("Humanoid")
		h.Died:Connect(function()
			if plr.InGame.Value == true then
				plrsLeftInGame = plrsLeftInGame - 1
				print(plr.Name.." has died.")
				plr.InGame.Value = false
			end
		end)
	end)

Any help would be greatly appreciated. Thanks!

1 Like

Have you tried making a print statement in your event function to see if the event doesn’t run entirely?

If you haven’t, you should try that, as most likely it’s a problem with your condition statement.

Apart from this, you could try writing a line to yield until the instance of the character appears in the workspace, as I’ve experienced some problems with .CharacterAdded firing before the character is parented or created properly.

repeat wait() until workspace:FindFirstChild(plr.Name)

Hope this helps

2 Likes

Hello,
This code:

plr.CharacterAdded:Connect(function(char)
		print("Local H")
		local h = char:FindFirstChild("Humanoid")
		print("Got H")
		h.Died:Connect(function()
			print("H Died Function")
			if plr.InGame.Value == true then
				print(":O")
				plrsLeftInGame = plrsLeftInGame - 1
				print(plr.Name.." has died.")
				plr.InGame.Value = false
			end
		end)
	end)

seems to not print anything at all. It seems to be an issue with CharacterAdded.

Another note, from experience I’ve noticed if you don’t declare the .CharacterAdded event directly after you declare your .PlayerAdded event, this won’t fire when the player initially loads in the first time.

Assuming that’s the issue here

Example:

game.Players.PlayerAdded:Connect(function(plr)
--//no variables or other code before we set up the .CharacterAdded event listener
plr.CharacterAdded:Connect(function(char)

end)
end)
2 Likes

Hello, this seems to work now. Thanks a lot! I was stuck on this for a little bit, lol.

1 Like