How to stop every animation from playing in this crouching scriopt

So I have a crouching script that makes the player crouch when he presses “S” but the problem is that when you move to the left or right, he will play another animation instead of the crouching one.

Here is the script :

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
	for _, animation in ipairs(hum:GetPlayingAnimationTracks()) do
		if animation.Priority == Enum.AnimationPriority.Movement then 
			animation:Stop()
		end
	end
end)

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

The animation priority for crouch needs to be higher than the walking ones, where the walking ones would be core or movement, crouch would be action1, action2, action3, or action4.

Is there any way to change animation Priority in a script?

Animation.Priority = Enum.AnimationPriority.Action1
1 Like

Ok so it’s still kinda broken. When I crouch and I walk left or right, then the idle animations starts playing and if I let go of crouching, then I will start walking. I made the idle animation priority to movement.

Idle should be idle, movement should be core, and crouch should be action1 or above

1 Like

Still doesn’t work. I changed Idle animation to Idle, moving to left and right to movement and crouch to Action and still doesn’t work.

Could have to do with too many animations playing at once! You might need to disable walking animation while crouching, or add new walking crouch animations to play instead!

1 Like

Let’s just disable idle and walking animations when crouching is enabled. How can we do that?

Just play the animation with a higher animation weight set

loopidleanimation:Play(0, 15)
1 Like
if crouch then
     if walkinganim then
          walkinganim:Stop()
     end
     crouchinganim:Play()
end
1 Like

This just makes the crouch animation snap immediately to idle

How am I supposed to do that tho? Should I use a bool value for when the player walks or is idle?

Are you using custom characters all together or are you modifying the defalt Roblox PlayerModule and/or its scripts?

for i,v in pairs(character.Humanoid.Animator:GetPlayingAnimationTracks()) do
    v:Stop()
end

I forgot if the function is :Stop() but this will basically stop every single animation playing on the humanoid’s animator

1 Like

this still doesn’t work. Maybe I can show a video of the problem?