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

Why is this GUI for loop not working as intended?

Asked by 9 years ago

I have a script that fades in and out some text...

waittime = 0.1

script.Parent.LoadText.Text = "Test"
for i = 1,0,-0.1 do
    wait(waittime)
    script.Parent.LoadText.TextTransparency = i
end

This script works perfectly, but because it increments by -0.1 its not smooth. So I decided to do this:

waittime = 0.01

script.Parent.LoadText.Text = "Test"
for i = 1,0,-0.01 do
    wait(waittime)
    script.Parent.LoadText.TextTransparency = i
end

for i = 0,1,0.01 do
    wait(waittime)
    script.Parent.LoadText.TextTransparency = i
end

Wait time is now 0.01 and it increments by -0.01. I assumed this would make the fading smoother and it does... except it takes forever and gets stuck at 0.01 transparency when it fades back out. This is undesirable because you can still see the text in the background after its faded away. Whats going on here? Can anyone help?

1 answer

Log in to vote
1
Answered by 9 years ago

Try that out, it work fine for me when I tested it. Just set the transparency, after a loop.

script.Parent.LoadText.Text = "Test"

for i = 1, 0, -0.05 do
    wait()
    script.Parent.LoadText.TextTransparency = i
end
script.Parent.LoadText.TextTransparency = 0

for i = 0, 1, 0.05 do
    wait()
    script.Parent.LoadText.TextTransparency = i
end
script.Parent.LoadText.TextTransparency = 1

I also made a few changes, so it still is mooth and it doesn't take forever due to "local lag"

0
Thanks! MasterDaniel 320 — 9y
Ad

Answer this question