Humanoid.Died only detect Died when player's health is set to 100

Something strange I noticed is that a player.died function (local script):

Player.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")
	humanoid.Died:Connect(function()
		print("died")
	end)
end)

only detects a die for damage parts when I do two things:

  1. set players health to -1
  2. set players health to 100 shortly before, otherwise my character resets, but no Died is detected
for _, v in pairs(workspace.Damagebricks:GetChildren()) do
	if v.Name == "Damage" and (v:IsA("BasePart") or v:IsA("Part")) then
		v.Touched:Connect(function(hit)
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player then
				local humanoid = hit.Parent:FindFirstChild("Humanoid"
                if humanoid  then
					-- Reduce health by 10
					if humanoid.Health - 10 >= 1 then
						humanoid.Health = humanoid.Health - 10
					else
						humanoid.Health = 100
						task.wait()
						humanoid.Health = -1 
					end
				end
			end
		end)
	end
end

Is this normal behavior?

Yeah its normal behaviour because your character cant live on 0 health as it puts the humanoid state to dead already even if you change as quick as you think.Think of it this way if the humanoid health is less than 1 then the character is regarded as dead even if you try manipulating the health property back above or equal to 1.For instance, Bedwars has custom matches where host or co host can use commands to change healths.

Hey, thanks for the reply!
what I mean is that it only detects death if my health was set to 100 and then to -1. if it was for example 50 and then set to -1, nothing happens (would not work if I removed the humanoid.Health = 100 line), and I really do not know why that is

ok the Reasoning behind that is probably due to its humanoid MaxHealth property as roblox has a core default health script in the startercharacterscripts so like you said if your humanoid.health=50 and maxhealth is 100 then roblox health script is in the process of healing back to max health from its current health value so the task.wait pause would overlap with the health default script.

alright. is there an easier way to actually kill the player so a :Died function detects it? setting the health to 100, waiting and then to -1 feels so unprofessional…

The Humanoid:TakeDamage() method but it doesnt take account for forcefields to damage the player

This probably isn’t what you mean but like Humanoid.Health = 0 ?

Yeah its another professional way how else can you damage the character humanoid

Yeah but setting the Health to 0 directly also bypasses MaxHealth.

yeah your right either way there is really any other way or he could use task functions like spawn() and delay().

Actually I’m just noticing you for some reason are checking if the health is over 10 and only then removing health?
Just remove the health no matter what it currently is at.

if humanoid  then
	humanoid.Health -= 10
end

yeah doing that results in me respawning and stuff but then the strange thing happens. the local script humanoid:died() function doesnt print out anything. it prints out “died” when I set it to = -1 tho. it SOMEHOW works if I set my health to 100 and then to -1, checking health - 10 >= 1 so I know when to do that specific action, thus “killing” the player

then try this:

Humanoid:TakeDamage(Humanoid.MaxHealth)

################

does not work sadly