While your script does work, it wouldn’t be the simplest or most efficient method to do this if by “keep an animation from not ending” you mean keep it from automatically looping.
When you create an animation in the Animation Editor, there’s actually a button that you can use to control whether or not the animation is looped. It’s possible that this button may have been enabled when you created your animation, causing it to automatically loop in-game.
You should be able to correct this with the following steps:
Import your animation back into the Animation Editor using File > Import from within the editor
Disable the “Toggle Looping Animation“ button found next the “Move Scrubber to End” button
Export your animation to the same animation file by using File > Export and then selecting the same animation in the export window
You can find more information on looped animations in the following Developer Hub Article: Using the Animation Editor
If I understand you correctly, I don’t believe so. By setting the animation to not loop, stopping it manually using Stop() wouldn’t even be necessary because the animation would stop by itself after one complete cycle.
When implemented, this would mean that the Play() function would play the animation once per mouse click, ending it automatically at the end of each cycle.