Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to smoothly animate this Loading Bar?

Hello.

For a project I'm working on, there is a general purpose Timer GUI that is supposed to show time remaining. (Basically like a loading bar)

Here is my code for it: The timer bar is located under > StarterGui -> gameGui -> FloatTop -> gBar

if Request == "countDown" then
    gText.Text = "Intermission"
    gG.Visible = true
    gR.Visible = false

    gBar.Size = UDim2.new(1.087,0,0,4) -- Timer, original size
    gBar:TweenSize(UDim2.new(0,0,0,4), "InOut", "Linear", 15) -- Timer, new size, 15 sec. later

     for i = 15, 1, -1 do
        gTimer.Text = i
        wait(1)
    end
end

The problem is, it doesn't seem to work. How can I animate this line so it goes from size (1.087, 0, 0, 4) to (0, 0, 0, 4) in 15 seconds, smoothly?

1 comment

0

Your sizes don't make sense. (1.087,0,0,4) to (0,0,0,4) would make the bar dissapear since the x would be 0.

1 answer

You should change the size after/in the for loop.

-- Example

for i = 15, 0, -1 do
	gTimer.Text = i
	gBar.Size = gBar.Size - UDim2.new(0.07247,0,0,0)
	print(i)
	wait(1)
end

You can have it go faster/smoother/etc by changing the loop size and whilst doing so also changing the wait time and the amount the take away. So for example, you could start at 30 but change the wait time to .5 and divide the amount to remove by 2(in this scenario) just tune it till your satisfied.

Code would be something like this.

if Request == "countDown" then
    	gText.Text = "Intermission"
    	gG.Visible = true
    	gR.Visible = false
	gBar.Size = UDim2.new(1.087,0,0,4) -- Timer, original size

	for i = 15, 0, -1 do
		gTimer.Text = i
		gBar.Size = gBar.Size - UDim2.new(0.07247,0,0,0)
		print(i)
		wait(1)
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.