Hi, so I have a gui textbutton with a local script and an animation. When you click the textbutton an animation play and continues to play until you press the textbutton again, making the animation stop and you go back to idle animation.
I also need to make a keybinable one for computer users. The script below is for the textbutton gui, but does anyone know how to make it as a key?
local btn = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid",10) --gets and waits for player
local CanEmote = true
local CoolDown = 0
local debounce = false -- Debounce
local dance = hum:LoadAnimation(script:FindFirstChild("Anim1")) --this is currently a gui script, so this detects an animation in the textbutton
btn.MouseButton1Down:Connect(function() --detects when player presses the button, but i need it to be a key
if debounce == false then
debounce = true
if CanEmote == true then
hum.JumpPower = 0 -- this makes it so the player can't move while the animation plays
hum.WalkSpeed = 0
CanEmote = true
dance:Play() -- animation
end
elseif debounce == true then --detects if u press it again, making the animation stop and putting you back to idle
debounce = false
dance:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
end
end)
Let's say you press "R" the animation plays, continue to play, and then stops if you press "R" again. does anyone know how to do this? Any help is appreciated. I just what to understand this since I'm a beginner at making my own scripts. Thank you.

2 comments
So, my script is currently in a textbutton gui that also has a animation in it. Where would I put this one, and would I also put the animation with it? Also thank you for answering and explaining, I like to understand these things.
Never mind I got it to work. Thank you so much! This helped a lot, thank you!