Setting humanoid's health to positive nonzero at exactly the same time it was set to 0 negates the death of the humanoid

When a humanoid’s health is set to 0 and at exactly the same time the health is set to a positive nonzero, the humanoid is not put in the dead HumanoidState. This would imply that, with precise timing, deaths of humanoids through 0 health can be negated when the health is set to positive nonzero at that exact moment.

This may depend on the game played, but the default health regeneration script (1% health every second) could result in this as well.

This can be done through different scripts. One script that rapidly heals the humanoid over time will negate the death caused by another script that tries to set the Humanoid’s health to 0.

System information:

  • CPU: Intel(R) Core™ i7-10750H CPU @ 2.60GHz
  • Memory: 16,0 GB
  • GPU 0: Intel(R) UHD Graphics
  • GPU 1: NVIDIA GeForce RTX 2070 with Max-Q Design

Provided is a basic place with the character’s default health script modified to set the health to 0, followed immediately with the default health regeneration (+1% health). The player’s health stays at 1% health.
HealthBug.rbxl (41.6 KB)

Expected behavior

I expect the humanoid to enter the dead HumanoidState once health reaches 0 at any moment. Afterwards, the humanoid’s health can no longer be positive nonzero and the humanoid remains dead.

In this case, the humanoid should remain dead with 0 health, and the healing should not be applied, even if done at the exact same time.

5 Likes

I’ve experienced this a few times before. For example I touch a kill-brick in an obby but avoid dying due to health regeneration happening at the same time that my health is set to zero.

2 Likes

If you have a game and don’t want this happening, you can check if the humanoid died, and if not, retry

1 Like

Thanks for the report! We’ll follow up when we have an update for you.

2 Likes

Please! Any updates? My game always suffers from this I’d have to manually change the humanoid state to Dead.
A lot of games who have insta kill and change health to 0 also suffer from this (See: Criminality).

2 Likes

My team has taken a look at this and decided that this behavior is going to vary from experience to experience, and that for most experiences the established behavior is acceptable.

If you need more precision in how your damage and healing are resolved, place the following ModuleScript under StarterCharacterScripts:

local RunService = game:GetService("RunService")
local Humanoid = script.Parent:WaitForChild("Humanoid")

local PrecisionHealth = {}

-- when you want to change health by a *relative* value
function PrecisionHealth:ModifyHealth(amount)
	if Humanoid.Health > 0 then
		Humanoid.Health += amount
	end
end

-- when you want to set health to an *absolute* value
function PrecisionHealth:SetHealth(amount)
	if Humanoid.Health > 0 then
		Humanoid.Health = amount
	end
end

return PrecisionHealth

Just make sure to retrofit all of your scripts that modify Health to go through this script instead of doing it directly.

-:skull:

I think the issue is mainly because of the Health regen script, adding a while Humanoid:GetState() ~= Enum.HumanoidStateType.Dead do` fixed it.

2 Likes