While-do Loop Randomly Pauses During Playback

I have a while-do loop in a LocalScript to make a background effect in my main menu Gui.
But sometimes, at random, the loop pauses for about 3-5 seconds and then continues.

I thought that the script might be overloaded by coroutines or something, so I put all the different UI animations into separate ModuleScripts so they can run by themselves. Literally nothing changed, except for organization.

This is a summarized version of the module:

coroutine.resume(coroutine.create(function()
    while frame.Parent.Visible do
        RedStrips.Position = UDim2.new(-1,0,0,YOffset)
        YellowStrips.Position = UDim2.new(1,0,0,YOffset)
        OtherStrips.Position = UDim2.new(0,0,0,YOffset)

        RedStrips:TweenPosition(UDim2.new(1,0,0,YOffset) ... 3)
        YellowStrips:TweenPosition(UDim2.new(-1,0,0,YOffset) ... 3)
        OtherStrips:TweenPosition(UDim2.new(0,0,0,YOffset) ... 3) --OtherStrips changes definition
        wait(3)
    end
end))

coroutine.resume(coroutine.create(function()
    while frame.Parent.Visible do
        TopSet.Position = UDim2.new(0,0,-1,5)
        BottomSet.Position = UDim2.new(0,0,0,0)

        BottomSet:TweenPosition(UDim2.new(0,0,1,0) ... 3)
        TopSet:TweenPosition(UDim2.new(0,0,0,5), ... 3)
        wait(3)
    end
end))

Any help is appreciated!

1 Like

Replace wait(3) with wait()