It looks like events 10-17 are running on every tick? In this case using "wait 2 seconds" there is a very bad idea. This can explain why the game starts lagging and freezing. After a few seconds there will be hundreds of delayed actions which will start to trigger and change the "state" value uncontrollably.
Use Timer behavior if you need to do something with a delay.
Also, random(2,2) will always return 2. You need to use choose(1,2)