I’m trying to make an advanced regen system which heals the player every .5 seconds, however if they get stunned, the timer resets and stops until they arent stunned anymore, after which it will then wait .5 seconds again.
However, the problem I’m having is that if they stunned and unstunned, sometimes they heal right away, but I want it to wait .5 seconds before healing them AFTER they arent stunned anymore.
local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'
local Values = Character.Values
local Rate = Values.RegenAmount.RegenRate.Value
--------------------------------------------------------------------------------
while task.wait() do
print("checking")
if Values.Status.Stunned.Value ~= true and
Values.Status.Ragdolled.Value ~= true and
Values.Status.Grabbed.Value ~= true and
Humanoid.Health > 0
then task.wait(Rate)
print("final check")
if Humanoid.Health < Humanoid.MaxHealth and
Values.Status.Stunned.Value ~= true and
Values.Status.Ragdolled.Value ~= true and
Values.Status.Grabbed.Value ~= true and
Humanoid.Health > 0
then
Humanoid.Health += Values.RegenAmount.Value
print("healed")
end
else
continue
end
end
In simpler terms:
When they are stunned, don’t regen.
After they are stunned, wait .5 seconds to regen.