Humanoid.Died and Humanoid.HealthChanged sometimes doesnt fire. (also a few questions as well)

I want to make it so that my script runs for each player, updating a position value when you take damage so that if you die, a corpse can spawn which debris after 30 seconds. When you die, itll trigger a humanoid.died event which runs a seperate function thatll spawn corpse and etc. Right now, the function I made is pretty untested due to the fact I can’t reliably fire the events

Currently, I’ve tested this script multiple times by resetting, humanoid.died and humanoid.HealthChanged both go undetected around 75% of the time. I haven’t been able to create a solution for it, nor have I found a solution online that has worked for me.

I’ve also tried changing out humanoid with player:FindFirstChild("Humanoid) with the same results of sometimes working, sometimes not.

Also, I have a few questions.
If you die, will humanoid health changed fire before humanoid.died or no? If the answer is no, how would I be able to store the position of a character right before they died without a heartbeat or renderstepped event. If one of those events are needed, how would you go about with that.

Along with that, I’d like to know your ways of making corpses if they are efficient.

(Also ignore the starter character comments, I set them up so the lobby model wont count as a model, since I think startercharacters replace your default character and you’ll spawn as them, though I’m not too sure.)


game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.BreakJointsOnDeath = false
		print(humanoid)

		local oldHealth = humanoid.Health
		print("Ran")
		humanoid:GetPropertyChangedSignal("Health"):Connect(function()
			print("Ran")
			--if character.Name == "StarterCharacter" then
			if humanoid.Health < oldHealth then
				player.Corpse.Value = character.HumanoidRootPart.Position
			end

			oldHealth = humanoid.Health
			--else
			--	return
			--end
		end)



		--if character.Name == "StarterCharacter" then
		humanoid.Died:Connect(function()

			print('ran')
			local Corpse = character:Clone()
				
			character.Archivable = true
			Killed(player,Corpse)

		end)

		--else
		--	return
		--end
	end)
end)

Did you figure this out? I finally did for my game.

First: how do I detect death?
Answer: I test for death every time I deal damage. The reason is simple: I am coding my own death animations. I want several. Death animations won’t properly play after “Died” is detected (which as you point out, is inconsistent… more on that later). So right before triggering damage that results in death, I know death should happen. That’s when I run my code. I run the animation. I empty tables, stop services, and wait for the animation to end. Finally, if its an NPC, I destroy it instead of triggering death, and if it’s a player, I set health to 0.

Why is .Died inconsistent for me? Because I do not wait for functions to return. The same function could run many times simultaneously, resulting in attacks that hit, but can’t damage because another hit dealt the killing blow. I am still weeding out a few of these overlapping functions.

I may leave bodies lying about, I may not. For now, it doesn’t impact gameplay, so no I won’t. If I do, I will clone the character, dump it in an obstacles folder (so it won’t attack), and assign a death pose animation. I will know my death pose because I will know which death animation was selected.

This will apply whether the death was due to damage or other. For example, if I introduce petrification, I will introduce animations specific for this and include a death pose.

Yea I figured it out, tho I do appreciate the help. Your system sounds similar to what I figured out as well, (ie running scripts to reset them from the game, then finally destroying and loading their new character in the lobby). I avoided using .Died and just used the healthchanged event to check when their health becomes zero or less, along with disabling the death state of the player, so that they didnt immediately respawn and I could do all the information gathering before killing the player off.

1 Like