Since this appears to be a tile script and you're experiencing freezing issues, make sure your script tile has a 'Var number' attached. As for the script itself, here are a few errors/ issues that I found:
While the above script should work for what you want to do right now, you should consider running the script based upon a variable rather than a flag. Tile scripts that check for flags instead of variables have issues such as interrupting the town/ route name in the top-left corner if they're near the entrance of a map and grinding the player's speed down to zero (this is very noticeable when you're at full speed on a bike). You'll avoid those glitches and even be able to remove the '@start' segment of your script, saving you more space.
Check out this thread if you want to learn more about how to have scripts activate based upon a variable~