#How would I make my pathfinding AI keep detecting a part

1 messages · Page 1 of 1 (latest)

grizzled lagoon
#

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

ashen bane
#

I don't have that much knowledge with path finding but maybe you can show the goal to the AI always using loops?

hexed lake
#

loop

grizzled lagoon
#

How could I make the loop run forever and still execute the code below?

ashen bane
#

Task.spawn and While true do I think

#

task.spawn(function()
while true do
-- find goal
task.wait()
end
end)

fathom wadi
#

no

#

instead just use for loops

#

like this:

grizzled lagoon
#

?

fathom wadi
#

whats was your issue with the code again?

ashen bane
snow starBOT
#

studio** You are now Level 5! **studio

fathom wadi
#

he could use if not?

snow starBOT
#

studio** You are now Level 10! **studio

ashen bane
#

a

#

Right

#

Tell that to him

tough edge
grizzled lagoon
#

???