You want to avoid checking a boolean and then checking the inverted value. If you follow the code, if lockedOn is true, it is set to false THEN the very next line checks if it is false, (which it is, because you set it to false), and sets it to true again. You want to use ELSE in this situation so you only check the value once, and react to it. As it happens, a simpler solution is to toggle the boolean!