NPC Movement Stuttering

I’m trying to make an NPC for my game, however, the NPC lags back, and has jittery movement.
I’ve tried changing the values, but it has done little to help with the issue.


-- Services
local Pathfinding_Service = game:GetService("PathfindingService")


-- Important variables --
local Enemy_Folder = script.Parent
local AI_Config = Enemy_Folder:WaitForChild("AI_Config")

-- NPC Variables --
local Enemy_AI = Enemy_Folder.Parent
local My_Root = Enemy_Folder.Parent:WaitForChild("HumanoidRootPart")
local My_Humanoid = Enemy_Folder.Parent:WaitForChild("Humanoid")

-- AI Configs --
local Agro_Distance = AI_Config:WaitForChild("Agro_Dist").Value
local Damage = AI_Config:WaitForChild("Damage").Value
local Speed = AI_Config:WaitForChild("Speed").Value
local Running_Animation = AI_Config:WaitForChild("Running_Animation").Value
local Walking_Animation = AI_Config:WaitForChild("Walking_Animation").Value
local Render_Speed = AI_Config:WaitForChild("Render_Speed").Value

local AI_Can_Jump = AI_Config:WaitForChild("AI_Can_Jump").Value
local AI_Can_Climb = AI_Config:WaitForChild("AI_Can_Climb").Value

local Path = Pathfinding_Service:CreatePath()


-- Bool Variables --
local Running = AI_Config:WaitForChild("Running")
local Walking = AI_Config:WaitForChild("Walking")



while true do
	wait(Render_Speed)
	for i,v in pairs(game.Workspace:GetChildren()) do
		local root_part = v:FindFirstChild("HumanoidRootPart")
		if root_part then
			if (root_part.Position - My_Root.Position).magnitude <= Agro_Distance and v ~= Enemy_AI and not v:FindFirstChild("Enemy_Contents") then
				print(v.Name.. " is within the distance of this NPC.")
				Path:ComputeAsync(My_Root.Position, root_part.Position)
				print(Path.Status)
				if Path.Status == Enum.PathStatus.Success then
					for i,c in pairs(Path:GetWaypoints()) do
						My_Humanoid:MoveTo(c.Position)
					end
				end
			end
		end
	end
end

What should I do to fix this NPC?

Have you tried setting the primarypart’s network owner to nil?

i used RunService to actually let it handle the NPC pathfinding and for updating, I do this because it prevents exhausted timeout

1 Like