How to make Animation GUI start and continue when clicked, then stops animation when clicked again?
Asked by
5 years ago Edited 5 years ago
Hello, I am trying to make a GUI button where if you clicked, an animation would play, but I want it to continue with the animation until if you were to click again, the animation would stop.
I have it to where you can click a button and the animation works but it only plays the animation then stops when the animation is done, and if you clicked the button again the animation will happen again, and so on. I got the script from a youtube tutorial.
This is a LocalScript in a TextButton under ScreenGui.
01 | local btn = script.Parent |
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character or plr.CharacterAdded:Wait() |
04 | local hum = char:WaitForChild( "Humanoid" , 10 ) |
08 | btn.MouseButton 1 Click:connect( function () |
09 | if CanEmote = = true then |
13 | local dance = hum:LoadAnimation(script:FindFirstChild( "Anim1" )) |
16 | wait(CoolDown + dance.Length) |
In the local script there is an animation, which is named Anim1.
^^That is what I got from the video but I want the animation to continue until clicked again so I tried doing something in the middle but now the button won't work.VV
01 | local btn = script.Parent |
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character or plr.CharacterAdded:Wait() |
04 | local hum = char:WaitForChild( "Humanoid" , 10 ) |
08 | btn.MouseButton 1 Click:connect( function () |
09 | if CanEmote = = true then |
13 | local dance = hum:LoadAnimation(script:FindFirstChild( "Anim1" )) |
16 | btn.MouseButton 1 Click:Connect( function () |
17 | if CanEmote = = false then |
22 | wait(CoolDown + dance.Length) |
Does anyone know what needs to be added or changed to my script in order for my animation to continue until stopped? Beginner with scripting but I kind of know how to read scripts, so if you could also explain in detail that would be appreciated because I also want to understand what I'm getting wrong.
Any help is appreciated, thank you.