When my "Noob Bot" npc goes to PointB then it goes to truss part as i expected but instead of going back to PointA it goes back to pointB and repeats Here is the script:

local PathfindingService = game:GetService("PathfindingService")

local PATROL_DELAY = 2

local Noob = script.Parent local humanoid = Noob.Humanoid local humanoidRootPart = Noob.HumanoidRootPart

local pointA = game.Workspace.A local pointB = game.Workspace.B

local currentDestination = pointA

function walk()

local startingPosition = humanoidRootPart.Position
local goalPosition = currentDestination.Position


local path = PathfindingService:FindPathAsync(startingPosition, goalPosition)
local waypoints = path:GetWaypoints()


for waypointIndex, waypoint in pairs(waypoints) do
	local waypointPosition = waypoint.Position

	humanoid:MoveTo(waypointPosition)

	humanoid.MoveToFinished:Wait()
	
end	


if path.Status == Enum.PathStatus.NoPath then
	currentDestination = pointB
	if currentDestination == pointB then
		humanoid:MoveTo(game.Workspace.Truss.Position)
		currentDestination = pointA
		wait(1) 
		
		if path.Status == Enum.PathStatus.Success then
			currentDestination = pointA
		else
			currentDestination = pointB
		end
		
	end
	
else
	currentDestination = pointA
end

wait(1)
return walk()

end walk()

How do i make it to when it reaches the truss part it goes back to pointA

2 comments

0

Can you fit this in a code block? you missed some code out.

1

The script starts from "local PathfindingService = game:GetService("PathfindingService")