The issue is when I have it print Path.Status it says Enum.PathStatus.NoPath
I have a warning in there warn('NPC Path Failed! No path available. trying to reach: ' .. tostring(Goal.Name))
which is coming in the console, so above that I have printed Path.Status which once again is Enum.PathStatus.NoPath when there is clearly a path.
local function MainNPCFollowing(Character, Goal)
print('Main NPC function called.')
local Waypoints = {}
local Path = PathfindingService:CreatePath()
local WaypointIndex = 1
local Humanoid = Character:WaitForChild('Humanoid')
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
print('Passed variables')
for index, item in pairs(Character:GetChildren()) do
if item:IsA("BasePart") then
item:SetNetworkOwner(nil)
end
end
print('passed opti')
local function FollowPath()
Path:ComputeAsync(HumanoidRootPart.Position, Goal.Position)
Waypoints = {}
print('PS: ' .. tostring(Path.Status))
if Path.Status == Enum.PathStatus.Success then
Waypoints = Path:GetWaypoints()
WaypointIndex = 1
Humanoid:MoveTo(Waypoints[WaypointIndex].Position)
else
warn('NPC Path Failed! No path available. trying to reach: ' .. tostring(Goal.Name))
Goal.Transparency = 0
Goal.Color = Color3.fromRGB(255, 0, 4)
Goal.Material = Enum.Material.Neon
end
end
print('passed follow')
-- Fires when the humanoid finishes moving to it's path (according to the script)
Humanoid.MoveToFinished:Connect(function(Reached)
if Reached and WaypointIndex < #Waypoints then
WaypointIndex += 1
if Waypoints[WaypointIndex].Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid:MoveTo(Waypoints[WaypointIndex].Position)
end
end)
-- Fires when the path is blocked
Path.Blocked:Connect(function(BlockedWaypointIndex)
warn('Path blocked.')
if BlockedWaypointIndex > WaypointIndex then
FollowPath(Goal)
end
end)
FollowPath(Goal)
end
Any help is appreciated. Thanks
ASAP as this is a core feature in my game.
Note: I have more code above and below but this is the main function