Humanoid Taking Damage Once

So I’m making a vitality system, where if the hunger hits 0 it will start to damage the player. Once hunger hits 0 it only damages the player once and then stops, I’ve tried a couple different things now and nothing will make the script damage the player more than once.

If anyone could take a look at why the humanoid is only being damaged once that would be great! I’ve tried looking up a couple things now, haven’t found any solution that works.

Code:

repeat
			
	if hunger.Value > 0 then
					
		hunger.Value = hunger.Value -1
					
	elseif hunger.Value == 0 then
					
		chr.Humanoid.Health = chr.Humanoid.Health -1
					
	end
				
	wait(1)
			
until nil
1 Like

In my opinion, repeat wait until loops are quite bad. You should use an alternative for it.

I would personally use chr.Humanoid:TakeDamage(1) unless you want the health of a player to drop even if it has a force field on, because this function automatically checks for that.

Have you tried using a while loop?

while wait(1) do
   -- your code
end

What’s so bad about a repeat loop?

Just did this the player’s health is still stopping at 99.

Found an alternative! Still not working.

If this is in a server script then this should work fine, but the repeat until nil is a bit wonky. I’d use a loop that runs as long as the character is still alive

while chr.Humanoid.Health > 0 do
    if hunger.Value > 0 then
        hunger.Value -= 1
    else
        chr.Humanoid:TakeDamage(1)
    end

    wait(1)
end

Turns out it was because humanoids, by default, regen health and it was negating the damage that was being done to the humanoid giving off the perception that my script was broken.

Thanks to those that helped!

2 Likes

Oof. You can temporarily disable that default regen script by setting Character.Health.Disabled = true

It’s all good, I did it. Thank you though!

1 Like