Animation not working

Hello,

why my walk animation is not stopped and my sprint animation did not start?

Animate (for character, it’s a localscript)

local rf = game:GetService("ReplicatedFirst")
local rs = game:GetService("ReplicatedStorage")
local plr = game:GetService("Players").LocalPlayer
local character = script.Parent

local humanoid = character:FindFirstChild("Humanoid")

repeat task.wait() until humanoid

local walkAnim = script:WaitForChild("Walk")
local pauseAnim = script:WaitForChild("Pause")
local sprintAnim = script:WaitForChild("Sprint")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)
local pauseAnimTrack = humanoid.Animator:LoadAnimation(pauseAnim)
local sprintAnimTrack = humanoid.Animator:LoadAnimation(sprintAnim)

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
    if humanoid.MoveDirection.Magnitude > 0 then
        local getSprint = rs.Events.Movement.GetSprint:InvokeServer()
        
        if pauseAnimTrack.IsPlaying then
            pauseAnimTrack:Stop()
        end

        if not getSprint then 
            if sprintAnimTrack.IsPlaying then
                sprintAnimTrack:Stop()
            end
            
            if not walkAnimTrack.IsPlaying then
                walkAnimTrack:Play()
            end
        else
            if walkAnimTrack.IsPlaying then
                walkAnimTrack:Stop()
            end
            
            if not sprintAnimTrack.IsPlaying then
                sprintAnimTrack:Play()
            end
        end
    elseif humanoid.MoveDirection.Magnitude == 0 then
        if walkAnimTrack.IsPlaying then
            walkAnimTrack:Stop()
        end
        
        if sprintAnimTrack.IsPlaying then
            sprintAnimTrack:Stop()
        end

        if not pauseAnimTrack.IsPlaying then
            pauseAnimTrack:Play()
        end
    end
end)

Localscript to enable “Sprint”:

local UIS = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character

UIS.InputBegan:Connect(function(keycode, _gameProcess)
    if keycode.KeyCode == Enum.KeyCode.LeftShift and not _gameProcess then
        rs.Events.Movement.SetSprint:FireServer(true)
    end
end)

UIS.InputEnded:Connect(function(keycode, _gameProcess)
    if keycode.KeyCode == Enum.KeyCode.LeftShift and not _gameProcess then
        rs.Events.Movement.SetSprint:FireServer(false)
    end
end)

Script to update “Sprint”:

local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.Movement.SetSprint

event.OnServerEvent:Connect(function(plr, v)
    plr.Movement.Sprint.Value = v
end)

Where did you put the scripts?

Had this issue before and managed to fix it. Did you use WaitForChild to wait for the humanoid to load and replicate to the server before attempting to load an animation through it?

Look at the first script :>, I use FindFirstChild.