HumanoidStateType.Dead, false. How to make a humanoid back on its feet?

Hello,

I will keep it short and simple.

Here is a snippet of my code:


--Humanoid Death Disabled--
humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
local died = false
humanoid.HealthChanged:Connect(function(health)
	if health <= 0 then
		if not died then
			died = true
			wait(20)
			died = false
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, true)
			wait(3)
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
		end
	end
end)

I am aware that the top method does not work to make the player whose health is at 0 (dead) come back on his feet after 20 seconds. It will just continue being in a platformstanding state. My question is, how would you make it so after 20 seconds, humanoid is back on its feet?

You could probably use Humanoid:ChangeState to force the humanoid into a running state:

-- after waiting 20 seconds...
died = false
humanoid:ChangeState(Enum.HumanoidStateType.Running)
1 Like

I remember the idle movement state being RunningNoPhysics, so it’d probably be more appropriate to use that instead to force the Humanoid to an idle state. Running is for active Humanoids performing physics calculations.

Hi, I have tried the ChangeState method with both Running and RunningNoPhysics with no luck.

My humanoid just lays there regening health. How do I make it so the humanoid is no longer under the influence of his health being at 0? So it can get up and start walking after regening health 25.

https://gyazo.com/c0ee55b0e3f96b27e917c2dabd9524df

1 Like

Could you show what you’re currently working with, or has it not changed since you posted it in the OP?

Frankly, anything to do with Humanoids is super hacky, espcially trying to force the death state off. I feel like you’d have more luck using a lower-level hack such as forcing the Humanoid health to be above 0.01 and treating any health below 1 as a pseudodeath state.

There are some example games that you can look at, e.g. Rogue Lineage has this kind of death system where when you die, you drop for 20 seconds and start walking after.

In Rogue Lineage, the character doesn’t actually die, because the health bar is still slightly above 0. I would just do what @colbert2677 described, and just set their health very close to 0 instead. You can just fork the Health script from your in-game character, and make the health bar stop regenerating for a short time before regenerating again if their health is below a threshold.
For example, this would be the default Health script:

local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 1 -- Wait this long between each regeneration step.

local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'

while true do
	while Humanoid.Health < Humanoid.MaxHealth do
		local dt = wait(REGEN_STEP)
		local dh = dt*REGEN_RATE*Humanoid.MaxHealth
		Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
		print(Humanoid.Health)
	end
	Humanoid.HealthChanged:Wait()
end

You can insert an if statement before running the while loop to see if you should make the character stop regenerating. Spoiler, this is pseudocode:

while true do
	if Humanoid.Health < 1 then -- or something
		wait(20)
		Humanoid.Health = Humanoid.Health + 1
	else
		-- run the usual while loop
	end
	-- health changed wait
end
1 Like

You also do need to force clamp the Health. Stopping regeneration at a certain point isn’t enough because if the Humanoid takes a large enough damage value, they will die. Keeping it in the while loop will cause this to happen: setting it immediately upon a registered health change will not.

Humanoid.HealthChanged:Connect(function (newHealth)
    Humanoid.Health = math.clamp(newHealth, 0.01, Humanoid.MaxHealth)
end)

From there you could probably just add an extra condition to that while loop.

while Humanoid.Health < Humanoid.MaxHealth and Humanoid.Health > 1 do
7 Likes