Npc movement isnt smoth

hello ! someone know why my npc moving so jitter , and how to fix it !


local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local PathFindingService  = game:GetService("PathfindingService")
local NPCSetting = require(script.Parent:WaitForChild("NPC"))

function NoPath(hum,humrp)
	local Rand = math.random(-10,10)
	local needtoreach = humrp.Position  + Vector3.new(Rand,0,Rand)
	local path2 = PathFindingService:CreatePath()
	path2:ComputeAsync(humrp.Position , needtoreach)
	local wp1 = path2:GetWaypoints()
	for i ,v in pairs(wp1) do
		hum:MoveTo(v.Position)
	end
end

function CreatePath(target,demonroot,demonhum)
	local Path = PathFindingService:CreatePath()
	Path:ComputeAsync(demonroot.Position , target.Position)
	local wp = Path:GetWaypoints()
	if Path.Status == Enum.PathStatus.Success then
		for i ,waypoint in pairs(wp) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				demonhum.Jump = true
			end
			local distance 
			local waypointPosition = waypoint.Position
			demonhum:MoveTo(waypointPosition)
			repeat 
				distance = (waypointPosition - demonroot.Parent.PrimaryPart.Position).magnitude
				wait()
			until
			distance <= 5
			
		end
	else
		NoPath(demonhum,demonroot)
	end
end
while true do
	RunService.Heartbeat:Wait()
	for i ,v in pairs(CollectionService:GetTagged("LowRankDemon")) do
			if v:FindFirstChild("Humanoid") and v:FindFirstChild("HumanoidRootPart") then
				local Hum = v.Humanoid
			local HumRP = v.HumanoidRootPart
			HumRP:SetNetworkOwner(nil)
				local Animate = v.Animate
				if Animate.Disabled == true then
					Animate.Disabled = false
				else
	--do nothing
				end
				for i ,enemy in pairs(game.Workspace.Livings:GetChildren()) do
					if enemy:FindFirstChild("Humanoid") and enemy:FindFirstChild("HumanoidRootPart") then
						local enemyhum = enemy.Humanoid
						local enemyhumrp = enemy.HumanoidRootPart
						local distance = (enemyhumrp.Position- HumRP.Position).Magnitude
						if distance <= NPCSetting["Demon"].Property.Range then
							CreatePath(enemyhumrp,HumRP,Hum)
						else
							NoPath(Hum,HumRP)
							
						end
					end
					
				end
		end
	end
end

heres my npc:
https://gyazo.com/e58da544ded947cb4f90db87137151a9

Set NetworkOwnership of the NPC to nil(Server Only and use it once)
Model.PrimaryPart:SetNetworkOwner(nil)

uh i aready set it , now i want my npc move smother

I can’t do much since this is handled in the server, but try to render the NPC in the client(A normal part in the server while the whole model in the client)

It looks like your NPC is momentarily moving backwards. This may be due to the waypoints return being behind, a call to NoPath() (maybe it can’t find targets on some heartbeats), or maybe sometimes the paths take too long to compute and the async compute call returns late putting the first waypoint behind the NPC.

Anyways, I’ll be making a controller in addition to a pathfinder. It’ll take at most 2 lines to move your NPC, instead of these 50. Find out more here Polaris-Nav

1 Like