Hi, my script is not working, it plays the animation, but when I press it again, it just doesn’t stop. and I’m wondering how I would make the animation play if you pressed Y the first time and if you press y again the animation stops?
local plr = game.Players.LocalPlayer
local Key = game:GetService("UserInputService")
local char = plr.Character
local Frame = game:GetService('StarterGui').GUI.Frame
if not char then
plr.CharacterAdded:Wait()
end
local hum = char:WaitForChild('Humanoid')
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://86672075079690"
local animationtrack = hum:LoadAnimation(animation)
function playAnimation()
animationtrack:Play()
end
function StopAnimation()
animationtrack:Stop()
end
Key.InputBegan:Connect(function(input)
if Frame.Visible == false then
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.F then
playAnimation()
else
StopAnimation()
end
end
end
end)