This is too complicated for you but give it a try

image

We have a folder called path.
Each path is a number or waypoint.
The paths can split into different choices.

The idea is to create multiple paths

local PatrolIndex = 1
	local PatrolSubIndex = 1 -- probably for each path 
	local PatrolPaths = {} 
	local tins = table.insert
	local function MakePath(pathpart, Level)
		local amtpaths = 0
		for i,v in pathpart:GetChildren() do
			amtpaths+=1
			local index = #PatrolPaths
			tins(PatrolPaths, {v})			
			MakePath( v, Level + 1 )
		end
	end
	local Level = 1
	for i,v in npc.Path:GetChildren() do 
		MakePath(v, 1)
	end
	print(PatrolPaths)
	-- format we want
	PatrolPaths = { {},{} }

Wait what? What is the problem?

You need to make it so that
PatrolPath is a table where

It comes up with 3 paths or 2 paths.
Each layer or child is a waypoint.
When a waypoint has 2 childs then the path is split into two.

Thus another path is made.

Based on the image above. We would want maybe 3 paths made. They would all start from 1

Use the MakePath as a recursive function

Ah I see, it is a problem not a challenge

What’s the point of the Level variable? It just seems like you’re incrementing it each time you callback the function…?

What about this variable? It just is being incremented.

Well Level is meant to represent the Next child.

we are trying to get all the children from the single ancestor in order to form paths. The picture here

image

Would show 3 paths for example.
There will be 3 paths and 2 will share the same branch and 1 will branch off from the 2nd one.

It’s complex logic but chatGPT did it

local function ReturnPaths(part)
    local AllPaths = {}
    
    local function FindPaths(currentPath, currentPart)
        local children = currentPart:GetChildren()
        if #children > 0 then
            for _, child in ipairs(children) do
                local newPath = {unpack(currentPath)}
                table.insert(newPath, currentPart)
                FindPaths(newPath, child)
            end
        else
            -- reached end of path
            table.insert(currentPath, currentPart)  -- Include the last part in the path
            table.insert(AllPaths, currentPath)
        end
    end
    
    FindPaths({}, part)
    
    for i, path in ipairs(AllPaths) do
        print("Path "..i.." for "..part..":")
        for j, node in ipairs(path) do
            print(j, node)
        end
    end
end

ReturnPaths(npc.Path["1"])