Hi, I would like to know how I can make the walk animation stop when the player is crouching.
Heres the code:
--//Crouch
local CrouchFile = script:WaitForChild("Crouch")
local CrouchTrack
if not CrouchTrack then
CrouchTrack = Animator:LoadAnimation(CrouchFile)
end
local function Crouching()
IsCrouching = true
script.Parent.Values.Crouching.Value = true
task.spawn(function()
while task.wait() do
if not IsCrouching then
break
end
if humanoidRootPart.Velocity.Magnitude < 1 and IsCrouching then
CrouchTrack:AdjustSpeed(0)
else
CrouchTrack:AdjustSpeed(1)
end
end
end)
CrouchTrack:Play(.3)
humanoid.JumpHeight = 0
humanoid.HipHeight = -1
end
local function StopCrouching()
IsCrouching = false
script.Parent.Values.Crouching.Value = false
if CrouchTrack then
CrouchTrack:Stop()
end
humanoid.JumpHeight = 7.2
humanoid.HipHeight = 0
end
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.C and CanCrouch then
Crouching()
end
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.C and CanCrouch then
StopCrouching()
end
end)
Video:
The crouch animation priority is Action, so it is higher than the walk animation.