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

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

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")

2 comments

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

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

2 answers

✓ Accepted answer

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.

2 comments

0

Didn't bother to fix the repeated code?

0

This change wasn't needed either.

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.

1 comment

0

Much better answer as it suggests avoiding repetition.

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