Is there a way to regenerate a value after that value has not been modified for an extended amount of time?

So, I have a energy bar in my game. Currently, it either constantly regenerates, or it regenerates when it is completely depleted. I can’t find out a way to flag it as like “Don’t regenerate” until the value hasn’t been changed for two seconds. I’ve looked throughout google for awhile and that isn’t helping either.

1 Like

I would use tick for this.

local Num = tick()
local LastChecked = 0
Instance.Changed:Connect(function()
if Num - LastChecked > 2 then --If Num - 0 is greater than 2 then
LastChecked = Num --LastChecked = 2,4,6,8 ect...
end
end)
3 Likes