Hello!
I have a pathfinding script:
local NPC = script.Parent
local PathfindingService = game:GetService('PathfindingService')
local HRP = NPC:WaitForChild('HumanoidRootPart')
local Players = game:GetService('Players')
local Humanoid = NPC:WaitForChild('Humanoid')
HRP:SetNetworkOwner(nil)
local function GetPath(Target)
local Path = PathfindingService:CreatePath()
Path:ComputeAsync(HRP.Position,Target.HumanoidRootPart.Position)
return Path
end
local function WalkTo()
local Target = GetTarget()
local Path = GetPath(Target)
if Path.Status == Enum.PathStatus.Success then
local Waypoints = Path:GetWaypoints()
for _, Waypoint in pairs(Waypoints) do
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
else
print('Stuck!')
Humanoid:MoveTo(HRP.Position - Vector3.new(0,5,0))
end
end
while wait() do
WalkTo()
end
But it doesn’t work correctly.
Here is my map:
The npc just walks off the grass, and tries to get to me, but it just touched the green. Why doesn’t it go across the plank?!