Earlier today, while scripting my main menu, I wanted to add an aesthetic effect where a set of four dots would tween in order from left to right from visible to invisible. I got rid of it because I wasn’t sure whether I was using coroutines correctly or not, or if it would achieve my desired effect.
I don’t think seeing the object hierarchy is necessary, so I’ll provide you with an outline of the code I was using to attain this effect. Assume the variables I use already exist.
coroutine.wrap(function ()
while true do
if not Loading then coroutine.yield() break end
for n in next, #Dots:GetChildren()
local Tween = TweenService:Create(Dots["Dot"..n], TweenInfo, Goals)
Tween:Play()
Tween.Completed:Wait()
end
-- ^ Repeated to make them invisible below
end
end)()
This code is successfully able to attain the fade in effect that I desire for my main menu. The issue lies in halting this coroutine. I want it to stop only after the dots have been made invisible. That also spawns other issues that I wish to determine:
- Am I using coroutines right?
- How do I make the script not do anything until a full run of this goes? I’ve been thinking of creating a “pass” upvalue where its set to false at the top of the loop and true at the bottom, with
repeat wait() until Pass == true
around the bottom after preloading has finished. - If I’m not doing this right, how can I achieve an effect where a loading aesthetic runs in parallel to some other form of live-updating code? I want the loading percentage to update real time while this aesthetic is running, but I don’t want the next screen to progress until preloading is done AND the dots are invisible.