Make bar regenerate after 5 seconds

How exactly would I make a bar that regenerates after 5 seconds? It only waits 5 seconds once and regenerates and doesn’t wait another 5 seconds to regenerate?
The bar sizes down or up based on the number value inside it.

(Devforum moderators, PLEASE don’t lock and unlist this post again)

I’m just using mana as a stand-in, change it to whatever suits your need

local RegenRate = 10 -- change this to whatever you want it to regen per second
local WaitTime = 5 -- replace 5 with however you want to wait to regen
local ManaValue = 0
local MaxMana = 100
local LastDecrease = time()
    if time() - LastDecrease > WaitTime and ManaValue ~= MaxMana then
        ManaValue = math.clamp(ManaValue + RegenRate*DT,0,MaxMana)
        print("Mana is now at "..ManaValue)

Whenever you decrease your mana like when you cast a spell, set LastDecrease to time()
I didn’t test this so there may be errors but this is set up like how you should set yours up

What if I wanted to use a server script?


Heartbeat isn’t useable on the server.

If you want it to regenerate after 5 seconds, then you could use a while wait(5) do loop, after that you can tween or whatever you do.

I want it to continuously regenerate 5 until it’s 100 after waiting 5 seconds only once.

So if I am hearing this correctly, what you could do it make a tween last 5 seconds and tween it to the max position of your frame. The 5 seconds will only run once, and if you ever want to use it again, simply call the tween with tween:Play()

Hey Ive got it to work here is code:

local ts = game:GetService("TweenService")

local plr = game.Players.LocalPlayer
local char = plr.Character

local Humanoid = char:WaitForChild("Humanoid")

local tween = ts:Create(script.Parent.Frame.Frame,, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {Size = UDim2.fromScale(0.986, 1)})

	local tween2 = ts:Create(script.Parent.Frame.Frame,, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {Size = UDim2.fromScale(0.986, Humanoid.Health/Humanoid.MaxHealth)})

I don’t want a tween to tween the bar’s size or position I have a bar that updates based on a number value’s value, I want to wait 5 seconds (only one time) and then constantly update the number value’s value until it’s 100. (Sorry for being so unclear.)

Can you show examples of this “bar”

The bar is not important, I just want a script that regenerates the value of a number value to wait 5 seconds then continously add 1 until the value is 100.


for i = 1, 100 do
	(Whatever you value is).Value += 1

This is probably the best way I can think of since your not really explaining it well, or showing any ui

1 Like

Does the loop stop after it reaches 100?

Of course it does! for i = 1, 100 loops through 1 to 100.

Now you can change the 1 to whatever you want to fit your needs.

So for example you can do

for i = Value, 100 do

this will start at the value then go to 100!

Although you already marked this as solved, Heartbeat is useable on the server.