Help with moving to seperate points?

Hi. For my fighter plane PATROL AI, I want the aircraft to move through different points in the order A,B,CD.
So basically it goes to A, first, when it gets withen 100 distance, go to b, b 100 go to c, c goes to d, and d goes back a.
The problem is when it goes to A, it goes to B until it gets within 100 but goes back to A, and this repeats indefinitely.

local function moveTo(part)
	if (script.Parent.JapPlane.Position - part.Position).magnitude > 100 then
		local origincframe = engine.BodyGyro.cframe
		local dir = (script.Parent.JapPlane.Position - part.Position).unit
		local spawnPos = script.Parent.JapPlane.Position
		local pos = spawnPos + dir 	
		engine:findFirstChild("BodyGyro").maxTorque =,10000,10000)
		engine:findFirstChild("BodyGyro").cframe =, pos+dir)
local function orbit(target)
	local a = home.part1
	local b = home.part2
	local c = home.part3
	local d = home.part4
1 Like

You can try to add a repeat wait until JapPlane.Position matches part a or is near. Or maybe when the touch it calls a function that makes it moves to part B then part B function to C then D then repeat.

Just throwing out something that could possibly work.
Haven’t done roblox coding in a minute, so not 100% sure if it works.

1 Like