while(mouse_left == 1) { wait(1);} simply waits until the mouse button is released and then goes on with the script.
It has nothing to do with the trace function, the problem was that the counter did not increase by 1 but by 3 or 4, and the pan value was also increased with more or less then the given 30..
Problem solved, I had to remove two lines of the script.