Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the GUI close? Its keeps counting.

Asked by 6 years ago

Here is my current code, its in local script .

01local frame = script.Parent
02local text = script.Parent:WaitForChild("TextLabel")
03 
04for i=1,5 do
05    text.Text = "Loading Story Mode (1%)"
06    wait(1)
07    text.Text = "Loading Story Mode (5%)"
08    wait(1)
09    text.Text = "Loading Story Mode (15%)"
10    wait(1)
11    text.Text = "Loading Story Mode (20%)"
12    wait(1)
13    text.Text = "Loading Story Mode (25%)"
14    wait(1)
15    text.Text = "Loading Story Mode (30%)"
View all 48 lines...
0
your code does exactly what you program it to do, so what that does is print the loading from 1% to 100% 5 times SteamG00B 1633 — 6y
0
I don't this you understand how for loops work. Please take a look at this: https://developer.roblox.com/articles/Roblox-Coding-Basics-Loops lunatic5 409 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

It's because you're using a for loop but not including this bit into the loop:

1frame:TweenPosition(UDim2.new(-1,0,0,0),"In","Quart")

Since that part isn't in the loop, the script won't read it.

Edit: Though you don't need the for loop, I believe. so the new piece of code would be this:

01local frame = script.Parent
02local text = script.Parent:WaitForChild("TextLabel")
03 
04 
05    text.Text = "Loading Story Mode (1%)"
06    wait(1)
07    text.Text = "Loading Story Mode (5%)"
08    wait(1)
09    text.Text = "Loading Story Mode (15%)"
10    wait(1)
11    text.Text = "Loading Story Mode (20%)"
12    wait(1)
13    text.Text = "Loading Story Mode (25%)"
14    wait(1)
15    text.Text = "Loading Story Mode (30%)"
View all 48 lines...

Hope this helps.

0
Didn't bother to fix the repeated code? xPolarium 1388 — 6y
0
This change wasn't needed either. xPolarium 1388 — 6y
Ad
Log in to vote
1
Answered by
lunatic5 409 Moderation Voter
6 years ago
Edited 6 years ago

You are not using the for loop correctly. What your code will do is load from 1% to 100% 5 times. If you want it to increase by 5% every second, you need to use the for loop differently. Here's an example:

1local amtLoaded = 0
2 
3for i = 1, 5 do
4    amtLoaded = amtLoaded + 5
5    text.Text = "Loading Story Mode (" ..amtLoaded.. "%)"
6    wait(1)
7end

The for loop repeats whatever is inside of it the specified number of times. So in the sample above, it will add 5 to the variable amtLoaded each iteration and then change the text to the current percentage.

0
Much better answer as it suggests avoiding repetition. User#24403 69 — 6y

Answer this question