It's a timing issue - remove all the waittillframeends.

It's not a good idea to use any wait times while the game is loading and compiling.