so ive been working on this all day and basically my npc stutters or lags when it moves. it like freezes for a half a second pretty often

its supposed to follow the player even when they move

local function getpathfindingpath(entity, nearestplr)
	local entityPath = pathFindingService:FindPathAsync(entity.PrimaryPart.Position, nearestplr.PrimaryPart.Position)
	local waypoints = entityPath:GetWaypoints()
	return waypoints[2]
end

wait(5)
local function getwaypoints(v)
	local nearestplr = game.Players:WaitForChild('thenormalelevator3').Character  
	local waypoint = getpathfindingpath(v, nearestplr)
	return {waypoint, nearestplr}
end
for q,w in pairs(entity:GetChildren()) do
	if w:IsA('BasePart') then
		w:SetNetworkOwner(nil)
	end
end

runservice.Heartbeat:Connect(function()
local waypoints = getwaypoints(entity)
	local v = waypoints[1]
	if v ~= nil then
		local pos = v.Position
		entity.Humanoid:MoveTo(pos)
		
	end

	end)

here's my code

3 comments

0

Yeah the roblox Pathfinding sucks. I recommend using CreatePath instead of FindPathAsync because it's deprecated.

0

hm i was using createpath before with the same results but ill probably move back over

0

add a few wait() here and there it works sometimes but idk if itll be helpful really cause that removes a bit of lag