I overrided the default health script and i need help!

I want to reset the health regen timer every time the player gets damaged

im not getting errors but its not working

I’ve tried looking on yt and on this website cant find a fix.
Heres the code:

– Gradually regenerates the Humanoid’s Health over time.

local REGEN_RATE = 1/2
local REGEN_RATE2 = 1/5 – Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 5 – Wait this long between each regeneration step.


local Character = script.Parent
local Humanoid = Character:WaitForChild’Humanoid’
local HealthValue = Character.HealthV


while wait() do
Humanoid:GetPropertyChangedSignal(“Health”):Connect(function()
HealthValue.Value = false
wait(5)
HealthValue.Value = true
end)
if Humanoid.Health < Humanoid.MaxHealth and Humanoid.MaxHealth == 100 and HealthValue.Value == true then
local dt = wait(REGEN_STEP)
local dh = dtREGEN_RATEHumanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
elseif Humanoid.Health < Humanoid.MaxHealth and Humanoid.MaxHealth == 250 and HealthValue.Value ~= true then
local dt = wait(REGEN_STEP)
local dh = dtREGEN_RATE2Humanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
end

Do you know if the code is actively running when the game starts? Either way, yes or no, add some prints to sections of your code to tell which parts worked and which parts didn’t.

Yes the code works when i start the game. I think after the 5 seconds when it sets the value to true then it regens the player. But i was wondering if i could instead of setting the value to true i was trying to find a way to make the regen step timer reset after everytime the player is damaged