On door open - Logic problem

You should always copy the code that you post, not retype it.