AI animations not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello Developers, so I am trying to make an AI character, and everything was going well, the pathfinding works, attack works, but the animations kind of work.
    This is a visual example:

There is nothing in the script that stops the animation, to my knowledge.
This is the current AI script:

local myHuman = script.Parent:WaitForChild("Humanoid")
local myRoot = script.Parent:WaitForChild("HumanoidRootPart")
local head = script.Parent:WaitForChild("Head")
local lowerTorso = script.Parent:WaitForChild("LowerTorso")

function walkRandomly()
	local xRand = math.random(-50,50)
	local zRand = math.random(-50,50)
	local goal = myRoot.Position + Vector3.new(xRand,0,zRand)
	
	local path = game:GetService("PathfindingService"):CreatePath()
	path:ComputeAsync(myRoot.Position, goal)
	local waypoints = path:GetWaypoints()
	
	if path.Status == Enum.PathStatus.Success then
		for _, waypoint in ipairs(waypoints) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				myHuman.Jump = true
			end
			myHuman:MoveTo(waypoint.Position)
			local timeOut = myHuman.MoveToFinished:Wait(1)
			if not timeOut then
				walkRandomly()
			end
		end
	else
		wait(1)
		walkRandomly()
	end
end

function findPath(target)
	local path = game:GetService("PathfindingService"):CreatePath()
	path:ComputeAsync(myRoot.Position,target.Position)
	local waypoints = path:GetWaypoints()
	
	if path.Status == Enum.PathStatus.Success then
		for _, waypoint in ipairs(waypoints) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				myHuman.Jump = true
			end
			myHuman:MoveTo(waypoint.Position)
			local timeOut = myHuman.MoveToFinished:Wait(1)
			if not timeOut then
				findPath(target)
				break
			end
			if checkSight(target) then
				repeat
					myHuman:MoveTo(target.Position)
					attack(target)
					wait(0.1)
					if target == nil then
						break
					elseif target.Parent == nil then
						break
					end
				until checkSight(target) == false or myHuman.Health < 1 or target.Parent.Humanoid.Health < 1
				break
			end
			if (myRoot.Position - waypoints[1].Position).magnitude > 20 then
				findPath(target)
				break
			end
		end
	end
end

function checkSight(target)
	local ray = Ray.new(myRoot.Position, (target.Position - myRoot.Position).Unit * 40)
	local hit,position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
	if hit then
		if hit:IsDescendantOf(target.Parent) and math.abs(hit.Position.Y - myRoot.Position.Y) < 3 then
			return true
		end
	end
	return false
end

function findTarget()
	local dist = 75
	local target = nil
	local potentialTargets = {}
	local seeTargets = {}
	for i,v in ipairs(workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso") or v:FindFirstChild("HumanoidRootPart")
		if human and torso and v.Name ~= script.Parent.Name and v.Name ~= "Cannibal" and v.Name ~= "Psycho" then
			if (myRoot.Position - torso.Position).magnitude < dist and human.Health > 0 then
				table.insert(potentialTargets,torso)
			end
		end
	end
	if #potentialTargets > 0 then
		for i,v in ipairs(potentialTargets) do
			if checkSight(v) then
				table.insert(seeTargets, v)
			elseif #seeTargets == 0 and (myRoot.Position - v.Position).magnitude < 150 then
				target = v
				dist = (myRoot.Position - v.Position).magnitude
			end
		end
	end
	if #seeTargets > 0 then
		dist = 150
		for i,v in ipairs(seeTargets) do
			if (myRoot.Position - v.Position).magnitude < 150 then
				target = v
				dist = (myRoot.Position - v.Position).magnitude
			end
		end
	end
	return target
end

function attack(target)
	if (myRoot.Position - target.Position).magnitude < 5 then
		if target.Parent ~= nil then
			target.Parent.Humanoid:TakeDamage(35)
		end
		wait(0.4)
	end
end



function main()
	local target = findTarget()
	if target then
		myHuman.WalkSpeed = 14
		findPath(target)
	else
		myHuman.WalkSpeed = 8
		walkRandomly()
	end
end

while wait(0.1) do
	if myHuman.Health < 1 then
		break
	end
	main()
end

This is a open-sourced AI script from kangerujack, and I am 90% sure it is not because of his script, (though I modified it a bit). I have a feeling it is because of the Animate script, which is this one
image

I have only made a idle/walk animation and made sure to set the walk animation to the RunAnim & WalkAnim, I have no idea why this is happening and if anybody can help me resolve this issue it would be really appreciated. (P.S the animations are set to movement)

Maybe the open sourced one is deprecated or outdated, try getting the animate script from your character instead. You first playtest the game with your character, then find your character in the explorer tab, then copy all the codes inside the Animate local script, then get a server script and paste the code in it, parent it to the AI character and should be working. Make sure the rig type of the AI character is the same as your Roblox character.