It's because you need to have sleep functions / return random values.
Also a big help is to run the console, and find if there are any errors while running the script. This can cause the client to freeze like you have said.
Good read, my interact method in my scripts randomly finds a spot within the model's bounding box, thus randomly moving the mouse either 0 or 15 in either direction randomly choosing a spot.