.Died not working

I am trying to detect when a certain player dies but because the humanoid is deleted it doesn’t fire.

for _,colony in pairs(ants:GetChildren()) do
	colony.Queen.ChildAdded:Connect(function(queen)
		local player = Players:GetPlayerFromCharacter(queen)
		local humanoid = queen.Humanoid
				
		humanoid.HealthChanged:Connect(function()
			local HPercentage = (humanoid.Health / humanoid.MaxHealth) * 100
			
			print(HPercentage)
			if humanoid.Health <= 0 then
				print(player)
			end
			
		end)
		
	end)
1 Like

Where does it get deleted? Put your code there instead.

By default, it gets deleted when the character dies.

Maybe then detect when the humanoid is deleted instead?

Just change humanoid.HealthChanged to humanoid.Died, that way you won’t need the conditional statements to check the health and it will only run when the ant dies