Pathfinding move between points

Moving the dummy from A to B is fine, however how would I move the dummy back to A afterwards?

local Patrol_Delay = 5

local function Activate2WayPoints(key)  -- the key is the name of the dummy
	local StartPosition = NPCFolder.Guard[key..""].HumanoidRootPart.Position	-- Create start and end
	local EndPosition = NPCFolder.Waypoints[key.."_B"].Position
	
	local Path1 = PathfindingService:CreatePath()	-- Create path
	Path1:ComputeAsync(StartPosition, EndPosition)
	
	local waypoints = Path1:GetWaypoints()
	for _, waypoint in pairs(waypoints) do	-- Loop through waypoints
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Size = Vector3.new(0.6, 0.6, 0.6)
		part.Position = waypoint.Position
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace
		
		NPCFolder.Guard[key..""].Humanoid:MoveTo(waypoint.Position)
		NPCFolder.Guard[key..""].Humanoid.MoveToFinished:Wait()
	end
end

while wait(Patrol_Delay) do  -- Loop through a folder containing multiple dummies
	for _,Guards in pairs(Level1Folder.NPC.Guard:GetChildren()) do
		Activate2WayPoints(Guards.Name)
	end
end

Just make it go to A using the script?

What kind of answer is this?
I could just create another path and copy and paste all that code but that just seems inefficient.
What I want to do is apply something like this to my code, however I don’t know how.

But thats how I did it in my code, there is nothing special about this just do what you already have done

You mean you want to reuse the waypoints? You can go through tables backwards.
for i = #waypoints, 1, -1 do

You’re using a function. You could just add parameters of it. Don’t call my answer dumb because I’m proving a point.

1 Like