i have a script that makes a path to a certain part, however when i print(path:GetWaypoints()) it prints nil
this is the code im using for the path:
local destination = workspace.NunPath:GetChildren()
local points = {}
for _,part in ipairs(destination) do
table.insert(points,part)
task.wait()
end
--------
local point = points[math.random(1,#points)]
local path = PFS:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true
})
print(point) --PRINTS THE PART THAT THE NPC IS TRYING TO GO TO
path:ComputeAsync(npc.HumanoidRootPart.Position, point.Position)
print(path:GetWaypoints()) --PRINTS NIL
for _, waypoint in pairs(path:GetWaypoints()) do
print("should be working") --DOESNT PRINT!!!
this is the problem, the for _, waypoint never runs, and GetWaypoints is returning nil, however the path does fail because the path never runs
here is more code if needed:
local point = points[math.random(1,#points)]
--local path = getPath(RandomSafeArea.Position)
local path = PFS:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true
})
print(point)
path:ComputeAsync(npc.HumanoidRootPart.Position, point.Position)
print(path:GetWaypoints())
if path.Status ~= Enum.PathStatus.Success then
warn("noooooooooooo path failed")
end
for _, waypoint in pairs(path:GetWaypoints()) do
print("should be working")
if waypoint.Action == Enum.PathWaypointAction.Jump then
human.Jump = true
end
if waypoint.Action == Enum.PathWaypointAction.Walk then
human:ChangeState(Enum.HumanoidStateType.Running)
end
print("Moving Player")
human:MoveTo(waypoint)
human.MoveToFinished:Wait()
print("Nun Moved Player To Safe Area")
local RandomAggro = math.random(1,2)
if RandomAggro == 1 then
print("Friendly")
else
print("Aggro")
target.Head:Destroy()
target.Health = 0
end
end
By any chance do you have any objects in your workspace that are thousands of studs away from your main pathfinding area? Objects that are extraordinarily far away in the void can cause :CreatePath() to yield indefinitely
The other potential issue is that pathfindingservice is simply not able to create a path from point A to point B. Is there anything blocking the path? Are your walls/floors meshparts?
yes, if i remove the doors that block the room the NPC is trying to go to, the for _, waypoint works, buttttt how can i make the npc go to the room, ignoring the door in the way
(also on the side, when the npc is supposed to go to the waypoint and i print the waypoints position, it prints the players position instead of the waypoint)
just tried it and yes the waypoints get created however the waypoints are incorrect like i said here
and when i say “player” i mean the NPC goes to a player, then the code in this topic happens. when i print point.Position it prints correctly, but when i print waypoint.Position it prints incorrectly
local point = points[math.random(1,#points)]
--local path = getPath(RandomSafeArea.Position)
local path = PFS:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true
})
print(point)
path:ComputeAsync(npc.HumanoidRootPart.Position, point.Position)
print(path:GetWaypoints())
print(point.Position) --correct
if path.Status ~= Enum.PathStatus.Success then
warn("noooooooooooo path failed")
end
for _, waypoint in pairs(path:GetWaypoints()) do
print("should be working")
print(waypoint.Position) --incorrect
so this could be related to other code in the script, which is why i said this