How do I make the command 'repeat' repeat something forever?

I was making a memes of the day wall and I wanted to make it switch between 3 images. So I put a script and in that script I wrote:
local MemePart = script.Parent

wait(3)
MemePart.Meme1.Transparency = 0
MemePart.Meme2.Transparency = 1
MemePart.Meme3.Transparency = 1
wait(3)
MemePart.Meme1.Transparency = 1
MemePart.Meme2.Transparency = 0
MemePart.Meme3.Transparency = 1
wait(3)
MemePart.Meme1.Transparency = 1
MemePart.Meme2.Transparency = 1
MemePart.Meme3.Transparency = 0
wait(3)
repeat

I want it to keep repeating forever, How do I do that?

2 Likes

You can achieve this with a while loop.
Please keep in mind with an infinite loop, no code below the loop will be run (unless placed in a separate thread, preferably using coroutines)

while true do
    wait(3)
    MemePart.Meme1.Transparency = 0
    MemePart.Meme2.Transparency = 1
    MemePart.Meme3.Transparency = 1
    wait(3)
    MemePart.Meme1.Transparency = 1
    MemePart.Meme2.Transparency = 0
    MemePart.Meme3.Transparency = 1
    wait(3)
    MemePart.Meme1.Transparency = 1  
    MemePart.Meme2.Transparency = 1
    MemePart.Meme3.Transparency = 0
    wait(3)
end

Keep in mind all infinite loops need a wait or some sort of yield, or else they will hang and crash.

Alternatively, if you wanted to use repeat (as stated in the title)

repeat 
wait(3)
    MemePart.Meme1.Transparency = 0
    MemePart.Meme2.Transparency = 1
    MemePart.Meme3.Transparency = 1
    wait(3)
    MemePart.Meme1.Transparency = 1
    MemePart.Meme2.Transparency = 0
    MemePart.Meme3.Transparency = 1
    wait(3)
    MemePart.Meme1.Transparency = 1  
    MemePart.Meme2.Transparency = 1
    MemePart.Meme3.Transparency = 0
    wait(3)
until false -- effectively makes this run forever.
9 Likes

I re-add the local MemePart = script.Parent right?

1 Like

Nope, that doesn’t need to be in the loop. It can stay above.