Animation stops playing after I press another button

So I made a crouch mechanic that when the player presses S, he crouches and plays an animation. The player shouldn’t be able to move after crouching so I turned the walk speed to 0 when the player presses S.

The problem is that, when you crouch and you press any button that makes the player move (W,A,D), the animation stops playing and he goes back to playing idle.

I tried unbinding those keys when the player presses S but still didn’t work.

local plr = game.Players.LocalPlayer
local char = plr.Character

local hum = char:FindFirstChild("Humanoid")
local uis = game:GetService("UserInputService")

local Animator = hum:WaitForChild("Animator")
local CrouchAnim = game.ReplicatedStorage.Animations["Crouch Start-Up"]
local CrouchIdleAnim = game.ReplicatedStorage.Animations["Crouch Idle"]

local GetDownAnimation = Animator:LoadAnimation(CrouchAnim)
local LoopIdleAnimation = Animator:LoadAnimation(CrouchIdleAnim)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.S then
		GetDownAnimation:Play()
		GetDownAnimation.Stopped:Connect(function()
			LoopIdleAnimation:Play()
		end)
		hum.WalkSpeed = 0
	end
end)

uis.InputEnded:Connect(function()
	GetDownAnimation:Stop(0.)
	LoopIdleAnimation:Stop(0.5)
	hum.WalkSpeed = 16
end)
1 Like

maybe have a look at this, Animation Priority

still doesn’t work, I changed it to action and still doesn’t work.

You have to stop previous animations. If you have a sword swing going on during an idle, you want to stop the idle then play the sword swing for example

Can you make an example script please?

1 Like
idle:Stop()
swing:Play()
swing.Stopped:Wait()
idle:Play()
swing:Stop()