Animation won't stop playing

Video provided down below, it keeps playing the animation after I jump and fall down while not moving…

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

-- Remember to select the animation object and set the id to your own!
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)

local function playWalkAnimation()
	if not walkAnimTrack.IsPlaying then
		walkAnimTrack:Play()
	end
end

local function stopWalkAnimation()
	if walkAnimTrack.IsPlaying then
		walkAnimTrack:Stop()
	end
end

local function isMoving(speed)
	return speed > 0
end

humanoid.Running:Connect(function(speed)
	local currentState = humanoid:GetState()
	if isMoving(speed) and currentState ~= Enum.HumanoidStateType.Jumping and currentState ~= Enum.HumanoidStateType.Freefall and humanoid.FloorMaterial ~= Enum.Material.Air then
		playWalkAnimation()
	else
		stopWalkAnimation()
	end
end)

-- Stop the animation when the player lands after jumping
humanoid.StateChanged:Connect(function(oldState, newState)
	if oldState == Enum.HumanoidStateType.Freefall and newState == Enum.HumanoidStateType.Physics then
		if not isMoving(humanoid.WalkSpeed) then
			stopWalkAnimation()
		end
	end
end)

You’re checking if the walk speed is over 0 instead of their velocity. I would get the magnitude of the MoveDirection from the humanoid like this humanoid.MoveDirection.Magnitude

Here’s the revised script:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

-- Remember to select the animation object and set the id to your own!
local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)

local function playWalkAnimation()
    if not walkAnimTrack.IsPlaying then
        walkAnimTrack:Play()
    end
end

local function stopWalkAnimation()
    if walkAnimTrack.IsPlaying then
        walkAnimTrack:Stop()
    end
end

local function isMoving(humanoid)
    return humanoid.MoveDirection.Magnitude > 0
end

humanoid.Running:Connect(function(speed)
    local currentState = humanoid:GetState()
    if isMoving(humanoid) and currentState ~= Enum.HumanoidStateType.Jumping and currentState ~= Enum.HumanoidStateType.Freefall and humanoid.FloorMaterial ~= Enum.Material.Air then
        playWalkAnimation()
    else
        stopWalkAnimation()
    end
end)

-- Stop the animation when the player lands after jumping
humanoid.StateChanged:Connect(function(oldState, newState)
    if oldState == Enum.HumanoidStateType.Freefall and newState == Enum.HumanoidStateType.Physics then
        if not isMoving(humanoid) then
            stopWalkAnimation()
        end
    end
end)

I think it won’t happen again!