PathFinding | Need help

Hi, so I don’t get this issue whilst in studio but the NPC seems to get stuck and almost chug along when the checkpoint is reached, any way to solve this or any Modules I could use instead of this?

Module Code
local module = {}

function module.Move(Nill, Part, Humanoid)
print(Part.Name)
local Touched = false
local PathfindingService = game:GetService('PathfindingService')
local path = PathfindingService:CreatePath()

-- Compute the path
path:ComputeAsync(Humanoid.Parent.HumanoidRootPart.Position, Part.Position)

-- Get the path waypoints
local waypoints = path:GetWaypoints()

-- Variables to store waypoints table and zombie's current waypoint
local waypoints
local currentWaypointIndex

local function followPath(destinationObject)
	-- Compute and check the path
	path:ComputeAsync(Humanoid.Parent.HumanoidRootPart.Position, Part.Position)
	-- Empty waypoints table after each new path computation
	waypoints = {}
	if path.Status == Enum.PathStatus.Success then
		-- Get the path waypoints and start zombie walking
		waypoints = path:GetWaypoints()
		-- Move to first waypoint
		currentWaypointIndex = 1
		Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
		return true
	else
		-- Error (path not found); stop humanoid
		Humanoid:MoveTo(Humanoid.Parent.HumanoidRootPart.Position)
	end
end
local function onWaypointReached(reached)
	if reached and currentWaypointIndex < #waypoints then
		currentWaypointIndex = currentWaypointIndex + 1
		Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
		print(Part.Name .. ' 1')
	end
end
local function onPathBlocked(blockedWaypointIndex)
	-- Check if the obstacle is further down the path
	if blockedWaypointIndex > currentWaypointIndex then
		-- Call function to re-compute the path
		followPath(Part)
	end
end
-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)

-- Connect 'MoveToFinished' event to the 'onWaypointReached' function
Humanoid.MoveToFinished:Connect(onWaypointReached)

if Touched == false then
	Part.Touched:Connect(function()
		if Touched == false then
			Touched = true
		end
	end)
end

followPath(Part)

repeat wait() until Touched == true
return true
end

return module

1 Like

I would suggest you to code this in a server script.

1 Like

I’m using server script to use the module, wouldn’t that work?

1 Like

Okay, just tried it in the server script, same results.

1 Like

Try doing it with an ordinary script.

Have done, same results. Slow.

try attaching the script to a character.

It is inside of the character.

Oh, I tried doing a pathfinding script there earlier this week and nothing happened and it gave me no errors. Is this happening to you?

No errors, just being slow and having a delay.

Try this script

local function setNetworkOwnership(character)
	for _, basepart in pairs(character:GetChildren()) do
		if basepart:IsA('BasePart') then
			basepart:SetNetworkOwner(nil)
		end
	end
end

-- setNetworkOwnership(your_character)
1 Like

Thanks, I found out about :SetNetworkOwner not so long ago before your help, thanks anyways!