I have a health script, if you get hurt, after 6 seconds your health will start recovering faster than the common one until it reaches 100% . Problem is that if you get hurt again and the recovering health function is now running it doesn't stop, it continues to regen your health quicky and it stops only when your health reaches 100%. Is there a way to stop the function if the player gets hurt again while health is regening so if the player gets hurt again he needs to wait the 6 seconds again before his health starts recovering?
This is the code only for the health recovering function:
local regening = false
function RecoverH()
if regening then return end
regening = true
wait(6) --These are the seconds it has to wait to start the function :P
while Humanoid.Health < Humanoid.MaxHealth do
local health = Humanoid.Health
if health > 0 and health < Humanoid.MaxHealth then
health = health + 1 * 0.3
Humanoid.Health = math.min(health,Humanoid.MaxHealth)
end
end
if Humanoid.Health > Humanoid.MaxHealth then
Humanoid.Health = Humanoid.MaxHealth
end
regening = false
end

1 comment
Thanks for answering my question it's my second time asking something here. I tried it the way you put it but the problem continues, recovery doesn't stops until health reaches 100%