how would I change this script so that if the LMB is held down it loops the animation until it has stopped being held but if pressed once it plays the animation once?
This will cause the animation to loop if the button is being held, and to stop looping when the button is not being held. Keep in mind when you release the mouse button, animation will not immediately stop, it will rather reach to the end and then stop.