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.
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.
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!