The best way to do it is, store the old location and then compare it with the new one (make sure you set the pitch and yaw to 0)
To do it, in a Loop place a Set Variable: Set Location Direction, in the first slot put a variable of your choice (preferably LOCAL), in the second slot, put Game Value: Location and in the 3rd slot put a Vector(1,0,0) then place an If Variable: =, in the first slot put the same variable and in the second slot put a variable that will contain the old player location (it should be a GAME variable, let's call it %default old location), and put your code between the pistons, then after the pistons place a Set Variable: Set Location Direction, in the first slot put the %default old location, in the 2nd slot put a Game Value: Location and in the 3rd slot put a Vector(1,0,0). The reason we set the %default old location after the if is so we check if they are equal then set it, if we put the set variable before the if it will always be true (since we are updating before we check).