I have a module script that basically controls pathfinding in my game. I use the roblox pathfinding service. The problem is that, it's not even pathfinding even if I stand directly across to the npc without any barriers.
I don't know how it can even fail, since the npc and my player are standing right across to eachother on a flat surface. It fails in one function in the module script. I have looked at it a bunch of times and it doesn't make sense to me that it would fail.
I have made the same thing but rescripted it and it doesn't work too. Should I just make my own pathfinding or I have to fix stuff up in my script?
If you like here are the script snippets from the two scripts:
Module script:
function PathfindingClass:Compute(Object)
local Path = PathfindingService:CreatePath() -- creates a path
Path:ComputeAsync(HumanoidRootPart.Position, Object.Position)
local Waypoints = Path:GetWaypoints()
if Path == Enum.PathStatus.Success then -- if it is good to move
PathfindingClass:Move(Waypoints, Path)
return true
else
print("Pathfinding failed")
Humanoid.WalkToPoint = Object.Position
return false
end
end
function PathfindingClass:Move(WaypointsTable) -- move the npc
for index, Waypoint in ipairs(WaypointsTable) do
if Waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
else
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait(2)
end
end
end
Script:
while true do
wait(3)
PathfindingClass:Compute(game.Workspace:WaitForChild("123nabilben123").HumanoidRootPart)
end
-- every 3 seconds it makes a new path
It doesn't make sense for my script to fail since I'm standing in the npc's view directly without barriers or difficult surfaces.
