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
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.
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.