Repeat-Until loop seems to not work

Scroll up, it’s the for numeric loop.

1 Like

Just wanted to put on the record that I’ve been having issues with repeat until not stopping as well. The variable after until was definitely true but wasn’t halting the loop in my localscript.

I had used

repeat wait() until VariableThatIsTrue

And I tried breaking the code up as xPuff_le suggested above with

repeat wait()
until VariableThatIsTrue

And the loop was suddenly able to complete properly.

Even stranger, when I then changed the code back to

repeat wait() until VariableThatIsTrue

and the loop continued to halt correctly!t

The only thing I can figure is that the code’s text isn’t being properly parsed by Roblox, and you need to fool around with the literal layout of the code until Roblox actually starts evaluating the until section of the code correctly again.

Also, for the OP’s situation, you need to be very careful in evaluating things to an exact integer value, as Roblox only uses floats for most numerical values. This means that the transparency value could have been 0.9999999 in memory, and you don’t want to risk that value not evaluating to 1 in a comparison line of code. That is why you absolutely must get used to using <= and >= comparisons instead of using == unless you are 1000% certain that == will always work for your use case. In the OP’s situation, things like transparency do not evaluate to == 1 with absolute certainty. While it will work much of the time, sometimes it may not.

this works too

local block = script.Parent


repeat wait()
	block.Transparency = block.Transparency + 0.01
	block.CanCollide = false
until block.Transparency >= 1


wait(3)

block.Transparency = 0
block.CanCollide = true