Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add a crouch walk animation to a crouch script?

Asked by 3 years ago

So basically, I have a crouch script. It works and all that good stuff, but the problem is it only uses the Idle animation. I have an idle crouch animation and a crouch walk animation but don't know how to make it so it actually uses the crouch walk animation. Can I get a hand here?

Code stuff

local UIS = game:GetService('UserInputService')
local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
local Animations = Instance.new('Configuration', Character)

Animations.Name = 'Animations'

local CrouchAnimation = Instance.new('Animation', Animations)
CrouchAnimation.AnimationId = 'rbxassetid://7364277021'
CrouchAnimation.Name = 'CrouchAnimation'
local LoadCrouchAnimation = Humanoid:LoadAnimation(CrouchAnimation)
LoadCrouchAnimation.Looped = true

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.C or Input.KeyCode == Enum.KeyCode.C then
        if Humanoid.Health > 0 then
            Humanoid.WalkSpeed = 5
            Character.HumanoidRootPart.Running.PlaybackSpeed = 0.70
            LoadCrouchAnimation:Play()
            while wait() do
                if Humanoid.MoveDirection.Magnitude > 0 then
                    LoadCrouchAnimation:AdjustSpeed(0.5)
                else
                    LoadCrouchAnimation:AdjustSpeed(0)

                end
            end
        end
    end
end)


UIS.InputEnded:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.C or Input.KeyCode == Enum.KeyCode.C then
        LoadCrouchAnimation:Stop()
        Character.HumanoidRootPart.Running.PlaybackSpeed = 1
        Humanoid.WalkSpeed = 16
    end
end)

Answer this question