Code is not detecting all UnionOperations inside folders

function addOutlineToAllProvinces()
	for _, v in ipairs(workspace.Map:GetChildren()) do
		if v:IsA("Folder") then
			for _, city in pairs(v:GetChildren()) do
				if city:IsA("UnionOperation") then
					local outline = Instance.new("Highlight")
					outline.Adornee = city
					outline.Name = "Outline"
					outline.FillTransparency = 1
					outline.OutlineColor = Color3.new(0, 0, 0)
					outline.OutlineTransparency = 0
					outline.Parent = city
				end
			end
		end
	end
end
task.spawn(addOutlineToAllProvinces)

I tried different methods but I still get the same results.

1 Like

Hey! I took a look at your code — it’s mostly solid, but I think the issue might be that some of the UnionOperations are nested deeper inside models or folders within each province folder, and your current script only looks one level deep.

In your current loop:

for _, city in pairs(v:GetChildren()) do

…it only checks immediate children of each folder. So if any UnionOperations are inside models or other containers (like city.Model), they’ll be skipped.

Here’s how to fix it:

You can use a recursive function or GetDescendants() instead to find all UnionOperations inside the folder, no matter how deep they are.

Here’s a version using GetDescendants():

function addOutlineToAllProvinces()
	for _, provinceFolder in ipairs(workspace.Map:GetChildren()) do
		if provinceFolder:IsA("Folder") then
			for _, descendant in ipairs(provinceFolder:GetDescendants()) do
				if descendant:IsA("UnionOperation") then
					local outline = Instance.new("Highlight")
					outline.Adornee = descendant
					outline.Name = "Outline"
					outline.FillTransparency = 1
					outline.OutlineColor = Color3.new(0, 0, 0)
					outline.OutlineTransparency = 0
					outline.Parent = descendant
				end
			end
		end
	end
end

task.spawn(addOutlineToAllProvinces)

This should detect all UnionOperations, even if they’re nested inside other parts or models.

it still doesnt works. I think this is a technical problem…

I’m not sure exactly how your code or its structure looks, but I recommend thoroughly analyzing it—essentially running a full debug—to identify and understand the issues that are happening.