Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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.

01local btn = script.Parent
02local plr = game.Players.LocalPlayer
03local char = plr.Character or plr.CharacterAdded:Wait()
04local hum = char:WaitForChild("Humanoid",10)
05local CanEmote = true
06local CoolDown = 0
07 
08btn.MouseButton1Click:connect(function()
09 if CanEmote == true then
10  hum.JumpPower = 0 -- this makes it so the player can't move while the animation plays
11  hum.WalkSpeed = 0
12  CanEmote = false
13  local dance = hum:LoadAnimation(script:FindFirstChild("Anim1"))
14  dance:Play()
15 
View all 21 lines...

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

01local btn = script.Parent
02local plr = game.Players.LocalPlayer
03local char = plr.Character or plr.CharacterAdded:Wait()
04local hum = char:WaitForChild("Humanoid",10)
05local CanEmote = true
06local CoolDown = 0
07 
08btn.MouseButton1Click:connect(function()
09 if CanEmote == true then
10  hum.JumpPower = 0
11  hum.WalkSpeed = 0
12  CanEmote = false
13  local dance = hum:LoadAnimation(script:FindFirstChild("Anim1"))
14  dance:Play()
15 
View all 28 lines...

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.

1 answer

Log in to vote
1
Answered by 5 years ago

Use a debounce.

01local btn = script.Parent
02local plr = game.Players.LocalPlayer
03local char = plr.Character or plr.CharacterAdded:Wait()
04local hum = char:WaitForChild("Humanoid",10)
05local CanEmote = true
06local CoolDown = 0
07 
08local debounce = false -- Debounce
09 
10 
11btn.MouseButton1Down:Connect(function()
12    if debounce == false then
13        debounce = true
14        if CanEmote == true then
15            -- Dancing thingamajingy
View all 22 lines...

Make sure to use the order i used.

0
Script that stops the dance? There is no script that stops it. The animation just plays then ends. Or do you mean the script that puts you back to normal, like line 15-19 on the first script I showed? Aprilsaurus 48 — 5y
0
Hi so, it works but I still don't know what you mean by the script that stops the dance. When I click the button the animation works and it stays but then I can't go back to normal because I don't know what stops the animation. Aprilsaurus 48 — 5y
0
The part where it makes you go back to normal, sets your speed to normal and :Stop() the animations. AcrylixDev 119 — 5y
0
The script that puts you back to normal. AcrylixDev 119 — 5y
View all comments (2 more)
0
so this (line 16-19 in the first script I showed) >> wait(CoolDown + dance.Length) hum.JumpPower = 50 hum.WalkSpeed = 16 CanEmote = true Aprilsaurus 48 — 5y
0
Yes. AcrylixDev 119 — 5y
Ad

Answer this question