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 5 years ago

Here is my current code, its in local script .

local frame = script.Parent
local text = script.Parent:WaitForChild("TextLabel")

for i=1,5 do
    text.Text = "Loading Story Mode (1%)"
    wait(1)
    text.Text = "Loading Story Mode (5%)"
    wait(1) 
    text.Text = "Loading Story Mode (15%)"
    wait(1)
    text.Text = "Loading Story Mode (20%)"
    wait(1)
    text.Text = "Loading Story Mode (25%)"
    wait(1)
    text.Text = "Loading Story Mode (30%)"
    wait(1)
    text.Text = "Loading Story Mode (35%)"
    wait(1)
    text.Text = "Loading Story Mode (40%)"
    wait(1)
    text.Text = "Loading Story Mode (45%)"
    wait(1)
    text.Text = "Loading Story Mode (50%)"
    wait(1)
    text.Text = "Loading Story Mode (55%)"
    wait(1)
    text.Text = "Loading Story Mode (60%)"
    wait(1)
    text.Text = "Loading Story Mode (65%)"
    wait(1)
    text.Text = "Loading Story Mode (70%)"
    wait(1)
    text.Text = "Loading Story Mode (75%)"
    wait(1)
    text.Text = "Loading Story Mode (80%)"
    wait(1)
    text.Text = "Loading Story Mode (85%)"
    wait(1)
    text.Text = "Loading Story Mode (90%)"
    wait(1)
    text.Text = "Loading Story Mode (95%)"
    wait(1)
    text.Text = "Loading Story Mode (99%)"
    wait(1)
    text.Text = "Loading Story Mode (100%)"
end

frame:TweenPosition(UDim2.new(-1,0,0,0),"In","Quart")
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 — 5y
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 — 5y

2 answers

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

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

frame: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:

local frame = script.Parent
local text = script.Parent:WaitForChild("TextLabel")


    text.Text = "Loading Story Mode (1%)"
    wait(1)
    text.Text = "Loading Story Mode (5%)"
    wait(1) 
    text.Text = "Loading Story Mode (15%)"
    wait(1)
    text.Text = "Loading Story Mode (20%)"
    wait(1)
    text.Text = "Loading Story Mode (25%)"
    wait(1)
    text.Text = "Loading Story Mode (30%)"
    wait(1)
    text.Text = "Loading Story Mode (35%)"
    wait(1)
    text.Text = "Loading Story Mode (40%)"
    wait(1)
    text.Text = "Loading Story Mode (45%)"
    wait(1)
    text.Text = "Loading Story Mode (50%)"
    wait(1)
    text.Text = "Loading Story Mode (55%)"
    wait(1)
    text.Text = "Loading Story Mode (60%)"
    wait(1)
    text.Text = "Loading Story Mode (65%)"
    wait(1)
    text.Text = "Loading Story Mode (70%)"
    wait(1)
    text.Text = "Loading Story Mode (75%)"
    wait(1)
    text.Text = "Loading Story Mode (80%)"
    wait(1)
    text.Text = "Loading Story Mode (85%)"
    wait(1)
    text.Text = "Loading Story Mode (90%)"
    wait(1)
    text.Text = "Loading Story Mode (95%)"
    wait(1)
    text.Text = "Loading Story Mode (99%)"
    wait(1)
    text.Text = "Loading Story Mode (100%)"
    wait(2)
    frame:TweenPosition(UDim2.new(-1,0,0,0),"In","Quart")
    wait(1)


Hope this helps.

0
Didn't bother to fix the repeated code? xPolarium 1388 — 5y
0
This change wasn't needed either. xPolarium 1388 — 5y
Ad
Log in to vote
1
Answered by
lunatic5 409 Moderation Voter
5 years ago
Edited 5 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:

local amtLoaded = 0

for i = 1, 5 do
    amtLoaded = amtLoaded + 5
    text.Text = "Loading Story Mode (" ..amtLoaded.. "%)"
    wait(1)
end

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 — 5y

Answer this question