Im trying to make an Animation toggle on & off using a specific keybind (for this script i used Z) and I cant seem to do that, I need help on stopping the animation.

-- Keybind:
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local toggle = false
local Animation = Instance.new("Animation") 

function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Z then
if not toggle then
toggle = true
enabled = true

----------------------------------------------
spawn(function()
     if enabled then
		Animation.AnimationId = "rbxassetid://1132469004"
        local Track = Humanoid:LoadAnimation(Animation)
        Track:Play()
     end
end)
----------------------------------------------

else
toggle = false
--------------------------
Animation.AnimationId = "rbxassetid://1132469004"
local Track = Humanoid:LoadAnimation(Animation)
Track:Stop()
--------------------------
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

3 comments

0

I'm not that good with things like this but isn't there supposed to be a function that says after z is pressed once its pressed again then turn of the animation

0

does it start at all? cuz from my understanding the z should be lower case at line 10

0

Theres different types of keybind functions, it does work. But it never turns off...