Need help stopping an animation

I am creating a dance GUI in my roleplay game. I have a script setting up an animation, and I made sure the animation isn’t looped so that it stops after one play through.

Then I thought, what if the player wants to stop the animation midway through its playtime?

How can I make it so when the player clicks the TextButton for a second time, it then stops the currently going animation?

1 Like

Store the animation track in a table like

local animationTable = {
CurrentlyPlaying = nil;
}

Then check for this variable when playing the animation or second press.

if animationTable.CurrentlyPlaying then
animationTable.CurrentlyPlaying:Stop()
animationTable.CurrentlyPlaying = nil
end