Making sure player does not die

I am trying to make sure that the hit player only gets downed (2HP) when reaching below 2HP, but they still die regardless.

function Check(Health)
   if Main.Damage <= Health then
      return Main.Damage -- 45
   end
   return 0 -- Random check
end
if Victim.Health <=  Main.Damage then
   Victim.Health = 2
else
   Victim:TakeDamage(Check(Victim.Health))
end
Humanoid.HealthChanged:Connect(function()
    if Humanoid.Health < 2 then 
        Humanoid.Health = 2
    end
end)

Should work

Once a Humanoid’s Health reaches 0, it will automatically die, no exceptions.
There is no “reviving” here; you can’t set the Health back to 1 or any number greater than 0.
It won’t make it “alive” again.

I’ve seen many games use that though, mainly criminality, when the player reaches <1%hp health they go to downed state and slowly regain back health

You can test it yourself. I just did and it works fine, even setting my health to 0. Please check before being so confidently incorrect :slight_smile:

Hmmmm, that is because they have a “Custom” state.

That is to say, they have a “Health” value separate from the Humanoid. They listen to that value instead of the Health property of the Humanoid.

I mean I can use this but I would have to use :Once() since I don’t want a connection inside a connection

Just connect the event to begin with, and every time the character respawns it will automatically do it

A script in StarterCharacterScripts with this would do the trick:

local Character = script.Parent

local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.HealthChanged:Connect(function()
	if Humanoid.Health < 2 then 
		Humanoid.Health = 2
	end
end)
1 Like

after testing your script I can conform it didn’t worked

It worked when I tested it
No idea what you did to it

I figured i’ll just do this

-- Effects
if VictimHumanoid.Health <= 2 then
   VictimHuamnoid.Health = 2
   return
end
VictimHumanoid:TakeDamage(Main.Damage)

Try

function Check(Health)
   if Main.Damage <= Health then
      return Main.Damage -- 45
   end
   return 0 -- Random check
end
if Victim.Health <=  Main.Damage then
 Victim:TakeDamage(Victim.Health - 2)
else
   Victim:TakeDamage(Check(Victim.Health))
end

Alternatively you could do this:

function TakeDamage(humanoid, damage)
    humanoid.Health = math.max(humanoid.Health - damage, 2)
end

Best way to do this is to just check every time when you are trying to take health away that it stays above 0 before you actually subtract. Puzzled made a very great example on doing this.