I made customs stats for players. If the player gets damaged they cannot heal for 5 secs but the player still heals while printing "cannot Heal" which only happens if they recently took dmg.
if script.Parent.Parent.Name == "Backpack" then
print("player found")
local Hum = script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid")
local Speed = 30
local Health = 145
local Jump = 70
local Regen = 3
local RegenRate = 0.7 --seconds
local healing = false
local RecentDmg = false
Hum.MaxHealth = Health
Hum.Health = Health
Hum.WalkSpeed = Speed
Hum.JumpPower = Jump
oldhp = Hum.Health
Hum.HealthChanged:Connect(function(hp)
if hp < oldhp then
if RecentDmg == false then
print("Cannot Heal")
RecentDmg = true
wait(5)
RecentDmg = false
print("can be healed")
end
end
end)
while true do
local rate = wait(RegenRate)
if RecentDmg == false then
while Hum.Health < Hum.MaxHealth do
if Hum.Health < Hum.MaxHealth/2 then
print("Regen Has been Doubled")
Hum.Health += Regen*2
wait(rate/2)
else
Hum.Health += Regen
wait(rate)
end
end
end
end
end

3 comments
ook ty
Whenever I regen, "RecentDmg" is set to true so I have to wait 5 seconds each time I regen. how do I fix this?
Ah, there's another bug: you don't update
oldhpafter every Health change (at the end of the function). Also, is this a Script or a LocalScript? It needs to be a Script for the Health changes to actually take effect (otherwise you will only see the changes locally) - or use a RemoteEvent