Immortal Character Help

Hello, I am making a combat game and I want to make it so your character doesn’t “die”. It never reaches 0 hp, because I’m trying to make an animation play when the character “dies”. But I want it to be easily configurable.

I have this script done so far but it doesn’t work.

		local hum = char.Humanoid
		local Animator = hum.Animator
		hum.BreakJointsOnDeath = false
		hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
		local ST ='IntValue')
		ST.Parent = hum
		ST.Name = 'Stun'
		local hDebounce = false
			if (hum.Health == 0 and hDebounce == false) then
				hum.Health = 50

Is there an alternative way? I just want the character death to be animatable, and configurable.

When a humanoid’s “Health” property reaches 0 the humanoid’s state is repetitively set to “Dead”, this can’t be avoided by simply setting the “Health” property to some value greater than 0.

What you need to do is disable the humanoid’s “Dead” state (this must be performed while the humanoid is alive) while they should be invincible and then re-enable it again when the effect has worn off.

humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false) --Invincible.
task.wait(5) --Duration of animation/effect.
humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, true) --No longer invincible.

That’s literally what was in my code haha. Anyways, I figured out the problem.