Another way is to use a state machine (these are a great way to make a series of events happen in a certain order with a certain timing). It's more complicated initially, but it scales better if you need a lot of different steps or events.
global gameMode as integer
gameMode = 0
do
select gameMode
case 0
`In this mode, put all the game playing logic
`GAME PLAYING CODE HERE
if (goToNextLevel)
gameMode = 1
timer# = timer() + 5.0
endif
endcase
case 1
`In this mode, we are waiting for the timer to finish
if (timer() >= timer#)
gameMode = 2
endif
endcase
case 2
`In this mode is the code for moving to the next level
`LEVEL MOVING CODE HERE
if (doneMovingToNext)
gameMode = 0
endif
endcase
endselect
`Out here, you can have code that should run in every mode (like UI code)
sync()
loop
On Steam!