Repeat-Until loop seems to not work

Hello!

I have been attempting to use the repeat-until loop, however in this case it does not seem to stop the loop.

I have been playing around with the script for a while now, and I just need a fresh pair of eyes to tell me if there is something wrong.

I have tried using a while Transparency < 1 do loop, as well as a numeric for loop.

local block = script.Parent


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


wait(3)

block.Transparency = 0
block.CanCollide = true

EDIT: If I test it in studio the transparency of the block goes up past 1?
Not sure how or why.

ANOTHER EDIT: When I attempted the for loop before it didn’t work because I added an increment of 0.01.

2 Likes

Not sure why it won’t work, but for doing something a set amount of times, that is what a numeric for loop is for see what i did there

for i = block.Transparency, 1, 0.01 do
    block.Transparency = i
    wait(0.1)
end
11 Likes

I have also tried that, it does not work.

However, I will try it once more, maybe I did something wrong.

Try this;

repeat wait() -- Wait up here.
-- Code here B)
until
4 Likes

Alright, I’ll try it, thank you.

That makes absolutely no difference.

3 Likes

Move

 block.Transparency = 0

to before the loop. I think that maybe it starts with a transparency of 1 and therefore wouldn’t enter the loop.

1 Like

Did not work, no errors or anything.

Does it skip the loop completely or does it enter once?
(The repeat version)

1 Like

I read the question wrong… I thought the loop wasn’t working at all… Looking at it I don’t know what’s wrong, but maybe see if it’s in a client script (local) and if it isn’t is the transparency changing?

It is server sided, maybe my recent edit will spark an idea?

How do you call this code? Server-side scripts won’t run of themselves the same way scripts on the client will.

Maybe try doing;

until block.Transparency >= 1

That way if the transparency doesn’t add up to exactly 1, it will work if it’s higher.

It runs as soon as the script loads, I will implement it into a .Touched event afterwards.

A server script doesn’t run as soon as the script loads. You need to connect the code to something that will call it like a player joining, the server starting or a .Touched event as you said.

No, it seems to run fine, just the loop doesn’t stop.

1 Like

Have you checked so the value gets updated in every iteration?

Nope, but I found a solution already.
Thank you for the help anyways!

1 Like

What was the solution? :smiley: just curious.