Moving character sliding around when I try to move it with PathfindingService

What do you want to achieve?
I want to make a moving character.
What is the issue?
My script works fine (I think so because when I tested it on a dummy it worked), but I might have some things to change to fix the issue. Basically, when the character is following me it slides back and forth.
What solutions have you tried so far?
Didn’t have any possible solutions. The issue is NOT with the pairs loop.

This is how it looks like:
robloxapp-20220106-1257531.wmv (3.9 MB)

while true do
	for _, enemy in pairs(attackEnemies) do
		local specificEnemyData = enemyData[enemy.enemyId.Value]
		local closestCharacter = nil
		local distance = specificEnemyData.aggroRange
		local range = enemy.range
		for _, player in pairs(players:GetChildren()) do
			local character = player.Character
			if character then
				local humanoidRootPart = character.HumanoidRootPart
				local magnitude = (range.Position - humanoidRootPart.Position).magnitude
				if magnitude < distance then 
					closestCharacter = character
					distance = magnitude
				end
			end
		end
		if closestCharacter then
			if distance < specificEnemyData.notFollowDistance then
				
			else
				local path = pathfindingService:CreatePath(specificEnemyData.pathParameters) --{AgentRadius = 40,AgentHeight = 70,AgentCanJump = false,WaypointSpacing = 3,Costs = {deathZones = math.huge,possibleZones = 10} }
				local success, errorMessage = pcall(function()
					path:ComputeAsync(enemy.range.Position, closestCharacter.HumanoidRootPart.Position)
				end)
				if success and path.Status == Enum.PathStatus.Success then
					local waypoints
					local currentWaypoint = 0
					waypoints = path:GetWaypoints()
					local blockedConnection = path.Blocked:Connect(function(blockedWaypoint)
						if blockedWaypoint >= currentWaypoint + 1 then
							path:ComputeAsync(enemy.range.Position, closestCharacter.HumanoidRootPart.Position)
							waypoints = path:GetWaypoints()
						end
					end)
					while true do
						currentWaypoint = currentWaypoint + 1
						print(currentWaypoint)
						if waypoints[currentWaypoint] then
							enemy.bossModel.Humanoid:MoveTo(waypoints[currentWaypoint].Position)
						else
							blockedConnection:Disconnect()
							break
						end
						enemy.bossModel.Humanoid.MoveToFinished:Wait()
					end
				else
					print(errorMessage)
					return errorMessage
				end
			end
		end
	end
	wait(1)
end

Do you want your model to have a walking animation?

I’m planning on adding it later. It doesn’t have one right now.

I think it may be an issue with the Roblox Physics, could you try turning CanCollide to false for all the parts in the model?

Edit: In the 15th second in the video you have sent you can see how the horn collides with the wall and “pushes off” causing the model to slide.

If I do that, the character falls into the ground. Thanks for the reply, though.

Maybe you could try turning off CanCollide only for the horns, as they seem to be the cause of the problem. Or you could use some form of Collision Filtering.

The horns are not the only cause of sliding. If I used Collision Filtering, what would I turn collisions off with? I want the game to be realistic, don’t need any horns passing through parts.

If you want your game to be realistic and to not collide you could add ignore parts around the wall which can cause this sliding with Pathfinding Modifiers (although it’s a beta feature, you would need to enable) or perform raycasts to check if the model isn’t too close to the wall.