Pathfinding Delay Between Waypoints

function createpath(target)
	local agentparams = {
		AgentHeight = 2.5,
		AgentRadius = 2,
		AgentCanJump = false
	}
	local path = pathfindingservice:CreatePath(agentparams)
	repeat
		path:ComputeAsync(script.Parent.Parent.HumanoidRootPart.Parent.Torso.Position, target.Position)
	until path.Status == Enum.PathStatus.Success

	if path.Status == Enum.PathStatus.Success then
		local waypoints = path:GetWaypoints()
		return path, waypoints
	else
		warn("paathfinding failed player edition")	
	end
end

for i,v in ipairs(workspace.Chairs:GetDescendants()) do
	if v.Name == "Seat" then
		table.insert(seats, v)
	end
end



local path, waypoints = createpath(myseat)
		if path and waypoints then
			for _, waypoint in ipairs(waypoints) do
				local p = Instance.new("Part",workspace)
				p.Color = randomcolor
				p.Shape = "Ball"
				p.Size = Vector3.new(0.5,0.5,0.5)
				p.Position = waypoint.Position
				p.Anchored = true
				p.Material = Enum.Material.Neon
				p.CanCollide = false
				p.Transparency = 0.5
				table.insert(waypointparts,p)
			end
			
			for i, waypoint in ipairs(waypoints) do
				script.Parent:MoveTo(waypoint.Position)
				script.Parent.MoveToFinished:Wait()
			end
			
			for _,v in ipairs(waypointparts) do
				v:Destroy()
			end
		end

Whenever the NPC reaches a waypoint it will stop for a split second and then move again except it only happens after multiple npcs are already in the game since i have a script that spawnsan npc every 2 seconds so the first few npc’s walk normally but after the game spawns 10+ npc’s the delay between moving to the next waypoint begins.

and before you say anything yes the Primary Part of the npc is set to the server using SetNetworkOwner(nil)

1 Like

Have you checked if the NPCs you are spawning aren’t causing server lag?

1 Like