I have made a script that has made a 2 second animation, but I want to make it longer and end when the script does
The script doesn't set the animation's time.
To make the animation longer, you have to use the Animation Editor to set the time to something longer.