I have a pathfinding ai that goes to a part named "Goal". The issue is that if it doesn't find the part almost immediately it just stops trying. This is a big problem as I have a new goal spawn in where ever a player right clicks.
local PathfindingService = game:GetService("PathfindingService")
local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local goalPart = workspace:WaitForChild("Goal")
local path = PathfindingService:CreatePath({
AgentCanJump = true,
AgentCanClimb = true,
})
local success, errorMessage = pcall(function()
path:ComputeAsync(npc.PrimaryPart.Position, goalPart.Position)
end)
if success then
for _,waypoint in ipairs(path:GetWaypoints()) do
local part = Instance.new("Part")
part.Material = "Neon"
part.Anchored = true
part.CanCollide = false
part.Shape = "Ball"
part.Position = waypoint.Position
part.Parent = game.Workspace
humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
humanoid.MoveToFinished:Wait()
end
else
warn(errorMessage)
end
** You are now Level 5! **