How can I make it so unless they key is pressed again the animation will not stop?

So what I am confused about is how to make it so unless the player cliks the key again, the animation will not stop. When I test it in studio, if the player walks or does anything after they press the key, the animation stops, I don’t need that. here is my script:

local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Key = 'Q'
local Animation = Instance.new("Animation")
Animation.AnimationId = 'rbxassetid://5225812319'
local Debounce = true
UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	local KeyPressed = Input.KeyCode
	if KeyPressed == Enum.KeyCode[Key] and Debounce then
		Debounce = false
		local LoadAnimation = Char.Humanoid:LoadAnimation(Animation)
		LoadAnimation:Play()
		wait(2)
		Debounce = true
		
	end
end)

What should I add?

You can use AnimationTrack.Looped to loop the animation until the key is pressed again, then stop the animation using AnimationTrack:Stop().

2 Likes