NPCs stuttering when using Pathfinding

First for some context/variable explanations. HRPart is the humanoidrootpart of the NPC, and CauldronMain is a part in the workspace. The code is running in the model of the NPC. The excerpt posted below is wrapped in a while true do loop.
This is the code.

local Path = PathfindingService:FindPathAsync(HRPart.Position, CauldronMain.Position)
if Path.Status == Enum.PathStatus.Success then
	local Waypoints = Path:GetWaypoints()
	for i, Waypoint in pairs(Waypoints) do
		Humanoid:MoveTo(Waypoint.Position)
		local Connection
		if Waypoint.Action == Enum.PathWaypointAction.Jump then
			Humanoid.Jump = true
			Connection = Humanoid.Changed:connect(function()
				Humanoid.Jump = true
			end)
		end
		local Reached = Humanoid.MoveToFinished:Wait()
		if Connection then
			Connection:Disconnect()
		end
		if not Reached then
			break
		end
	end
end

When running it in play solo the monsters move normally, but when I play the actual game they stutter. In between every waypoint, for around 0.4 seconds their animation stops, and then resets. This looks really awful in-game and is very immersion-breaking, which is why I want to fix it.

If anyone wants to I can post the link to the game.

Check this out :slight_smile:

6 Likes

After modifying the code a bit (changing the distance etc) it worked. Solved!

3 Likes

There is an easier solution:
use :SetNetworkOwner(nil) on all baseparts of your npc.

2 Likes

We know that, and also it’s really late lol (Sorry for off-topic)

Well obviously the asker didn’t

1 Like