Context
So basically I am making a script that spawns NPC’s and moves them into a house using PathFindingService.
Only problem is, it always fails to pathfind.
I’ve have asked in multiple places and just cant seem to figure it out.
Questions others have asked
- Is the NPC unanchored? Yes
- Is it moving the right NPC? Yes I have gone and tested it. It is moving the right NPC.
- Errors? I does not print any errors. But I have made it so it prints the pathfinds Status. Which always returns as NoPath.
Code
-- events
local events = game:GetService('ReplicatedStorage'):FindFirstChild('NPCs events')
local setupBomb = events:FindFirstChild('SetupBomb')
-- entries
local entriePoints = workspace:FindFirstChild('Entrances')
local EPNumber = #entriePoints:GetChildren()
-- services
local pathFindingService = game:GetService('PathfindingService')
local attempts = 20
local function sendToPlace(npc,endPoint)
print(npc.Name)
warn('Pathfinding!')
local hum = npc:FindFirstChild('Humanoid')
local path:Path
for attempt = 1, attempts, 1 do
path = pathFindingService:CreatePath()
if path.Status == Enum.PathStatus.Success then
path:ComputeAsync(npc.PrimaryPart.Position,endPoint.Position)
local waypoints = path:GetWaypoints()
-- use the waypoints
for i, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum:MoveTo(waypoint.Position)
hum.MoveToFinished:Wait(2)
end
attempt = attempts
else
warn('Failed to pathfind!')
warn(path.Status)
end
task.wait(1)
end
end
local function enter(npc) -- make an NPC enter the building!
print('Making '..npc.Name..' enter the place!')
local entryPoint = entriePoints:GetChildren()[math.random(1,EPNumber)]
print('Entering at '..entryPoint.Name)
task.spawn(sendToPlace,npc,entryPoint)
end
setupBomb.Event:Connect(function(NPC) -- yes this does fire and run. It does it three times
wait(3)
task.spawn(enter,NPC)
end)
- So why is this happening?
- How can I fix it?
- Or is there another solution?
All help is appreciated!
~Froyo~