Hey guys, I made this pathfinding script. It works, but it's for a bot survival game and when the character moves, I know the bot won't follow it. How can I change this script so that the MoveTo() only runs once, then it resets and does it again?

PFS = game:GetService("PathfindingService")
Bot = script.Parent.Bot
Target = script.Parent.Target.Position
Start = Bot.Torso.Position
PointModel = script.Parent.PointModel
MakePointsTransparent = false

function MakePath(StartPoint, EndPoint)
	NewPath = PFS:ComputeSmoothPathAsync(StartPoint, EndPoint, 512)
	return NewPath
end

Path = MakePath(Start, Target):GetPointCoordinates()

function DoStuff()
	for _,point in pairs(PointModel:GetChildren()) do
		point:Destroy()
	end	
	
	for _,point in pairs(Path) do
		Part = Instance.new("Part")
		Part.Parent = PointModel
		Part.Anchored = true
		Part.Position = point
		Part.FormFactor = Enum.FormFactor.Custom
		Part.Size = Vector3.new(1,1,1)
		Part.CanCollide = false
		if MakePointsTransparent == true then
			Part.Transparency = 1
		end
	end
	
	for _,point in pairs(Path) do
		Bot.Humanoid:MoveTo(point)
		
		repeat
			Distance = (point - Bot.Torso.Position).magnitude
			wait()
			if point.y > 1 + Bot.Torso.Position.y then
				Bot.Humanoid.Jump = true
			end
		until Distance <= 3
	end
end

DoStuff()

1 comment

0

By "resets and does it again", what do you mean? Repeat the DoStuff() function?