How to make Lua wait for a for loop to finish?
I have a Gui menu. I want it so that when the player press 'Start', the menu buttons will fly away as the screen turns to black and while the screen is black, the camera will switch from the menu to the player.
06 | frame.BackgroundTransparency = i |
08 | for _,gui in pairs (menu:GetChildren()) do |
09 | gui:TweenPosition(UDim 2. new(- 1 , 0 , 0 , 0 ), "Out" , "Quint" , 5 ) |
14 | cam.CameraSubject = player.Character.Humanoid |
15 | cam.CameraType = "Custom" |
19 | frame.BackgroundTransparency = i |
This plays out in my head nicely but, when I press 'start' in the game everything fires off in totally the wrong order in such a messy way that makes my eyes sad. First of all, the Gui flies away before the screen is opaque (creating an awkward pause) and then the camera seems to switch before the Gui stops being opaque. It's like everything I'm doing is ignoring the for loop at the top of the code and going whenever they feel like it. Here is a gif to make things a bit clearer:
http://imgur.com/4BdOias