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

Why does this repeat loop continue beyond it's "until" threshold?

Asked by 3 years ago

I made an intro GUI that is intended to fade text in and out - to actually make it fade in and out I used a repeat loop. The script looks something like this:

       repeat wait(0.05)
       script.Parent.TextLabel.TextTransparency = script.Parent.TextLabel.TextTransparency - 0.1
       until script.Parent.TextLabel.TextTransparency == 0
end

This isn't the entire script, just an example of how it's set up. I have multiple different elements that are fading in, each on their own repeat loop. All the loops work just fine, except the one showcased above, which is the only one dealing with TextTransparency. The TextTransparency is set to 1 and the loop is supposed to stop when it reaches 0. It does not stop once it reaches 0 and continues into the negatives, putting the rest of the script on hold. The only solution I have is to replace this line

       until script.Parent.TextLabel.TextTransparency == 0

with this

       until script.Parent.TextLabel.TextTransparency >= 0

This works, but it doesn't stop at 0, it stops at -0.

The rest of the script uses the exact same format as the initial code and works as intended, breaking the loop when the transparency or volume of something reaches 0. It is JUST that bit, and I can't figure out why it's so bugged.

1 answer

Log in to vote
0
Answered by 3 years ago

I am not technically savvy with explaining things, but I can provide a solution. From what I believe, it is decreasing at intervals too quickly for the game to pick up. Below is code that should remedy the issue. I also went ahead and replaced:

script.Parent.TextLabel.TextTransparency = script.Parent.TextLabel.TextTransparency - 0.1

with:

script.Parent.TextLabel.TextTransparency -= .1

which is just less code to write. Secondly, I went ahead and added:

script.Parent.TextLabel.TextTransparency = 0

So once the loop completes, the transparency is set to the correct value. Below is the full code:

repeat wait(0.05)
    script.Parent.TextLabel.TextTransparency -= 0.1
until script.Parent.TextLabel.TextTransparency <= 0

script.Parent.TextLabel.TextTransparency = 0
Ad

Answer this question