How to add 1 health point per 2 seconds

I have been trying to code a health charger but am stuck on making it only add 1 health point per 2 seconds. I have searched the wiki and have tried to use timers but it has not helped me.

function ENT:Use(act , call)

if call:Health() >= 100 then return false end

local durability = self:GetHealthChargerDurability() - 1
local durabilitysave = self:SetHealthChargerDurability(durability)
local health = call:SetHealth(call:Health()+1)

end

This is my function i use on the entity please help me

A way you might do this is to give the player a limit as to the amount of times they can call the function in a certain amount of time can be called using something like “CurTime()”.

Here’s an example:


function myFunction( ply )
    if( ( ply.LastFunctionCall or 0 ) < CurTime() )then -- This checks if the player can run the function after a certain amount of time.
        -- Run the code.
        ply.LastFunctionCall = CurTime() + delay -- This just sets the next time they can call the function.
    end
end

You could add a variable NextChargeTime = CurTime()+2 and then return if CurTime() is below NextChargeTime.
1 minute late q.q