0

# How do I stop my pathfinding NPC from freezing?

Edited 6 days ago

I have a pathfinding NPC which obviously intends to go from one location to another, however I encounter this problem where I found that if I am not anywhere near the NPC, it just stops moving. I understand that this might be a NetworkOwnership type of issue thing but I have already set the ownership to the server. I have used pathfinding on this NPC 3 times with no errors whatsoever and can also function when no players are nearby, except the fourth time in which it just freezes when no players are nearby. My script is 188 lines long so this is the gist of the issue since everything else works fine

local RainDroutz = workspace.collisionNPC.RainDroutz

local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local waypoints = path:GetWaypoints()

-- pathfinding
function pathfinder()
local waypoints = path:GetWaypoints()

for i, waypoint in ipairs(waypoints) do
RainDroutz.Humanoid:MoveTo(waypoint.Position)

if waypoint.Action == Enum.PathWaypointAction.Jump then
RainDroutz.Humanoid.Jump = true
end

RainDroutz.Humanoid.MoveToFinished:Wait()
end
end

game.ReplicatedStorage.GameStart.OnServerEvent:Connect(function()

game.ReplicatedStorage.ObjectiveTimer1:Fire()

path:ComputeAsync(RainDroutz.HumanoidRootPart.Position, workspace.Movementparts.RDMove4.Position)
pathfinder()
end)