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)