How can i make a delay before a player is able to regenerate again?

I wanted to add a delay before a player could be able to heal for my game.

the issue is that i don’t know how i can restart the 3 second timer again if the player get hit again before the 3 second ends.

for example if you get hit 2 times, you will regen for like half a second after the first hit then will be set to false again.`

I want the delay time to reset back to 3 seconds without you healing in between if you get hit a second or mutiple times within this delay time

here’s the script:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local oldHealth = humanoid.Health

local damaged = Instance.new("BoolValue")
damaged.Name = "damaged"
damaged.Value = false
damaged.Parent = character

while wait() do
	humanoid:GetPropertyChangedSignal("Health"):Connect(function()
		local delayTime = 3

		if humanoid.Health < oldHealth then
			damaged.Value = true
			wait(delayTime)
			damaged.Value = false
		end

		oldHealth = humanoid.Health
	end)
end
3 Likes

Look into debouncing. That’s all Debounce Patterns | Documentation - Roblox Creator Hub


I tried something else but for some reason it doesn’t reset back to 3 and instead starts a new delay time. the timer still goes to zero instead of restarting


I think I got it to work properly now

1 Like