Check If Parts Have Same Name Then Union

So I have this generation via parts, once all generated I want to loop through a folder that has all the generated parts, then go through each one and union all parts with all same names.

So if I have 100 parts named Grass, 100 Parts named sand, 100 parts named water I want to union each one with thier own names.

I am not sure how you would go about this?

Check out this dev forum post, it should help you with what you want. How do I create unions with a script? - #2 by theking48989987, just go thru workspaces descendants, if theres a specific name put it in a table with everything and union it

Could you provide a small example? LIke how I would go into the folder in workspace, find how many dupliactes of what there are and then anchor all them?

I didnt notice the anchor part, i basically wrote what you wanted, should work local partsForUnion = {}; --create a array for us to put parts in, example, 2 parts named sand -> ["sand"] = {sandPart1, sandPart2} local countForParts = {}; --lets us count so we can actually check if we need to; local maxParts = 15; for i, v in pairs(workspace:GetDescendants()) do if not v:IsA("BasePart") then continue; end if not countForParts[v.Name] then countForParts[v.Name] = 0; partsForUnion[v.Name] = {}; end countForParts[v.Name] += 1; table.insert(partsForUnion[v.Name], v); end; for i, v in pairs(countForParts) do if v > maxParts then for _, parts in pairs(partsForUnion) do local firstPart = parts[1]; table.remove(parts,1); firstPart:UnionAsync(parts); end end end;

function polisher(terrainTable)
local maxY = -100

for i, v in pairs(terrainTable) do
	if v[1] > maxY then maxY = v[1] end
end

for i, v in pairs(terrainTable) do
	local Y = math.floor((v[1] / maxY) * 100) 
	local Type

	for i, v in pairs(TerrainHeightsList) do
		if Y > v.Height then
			Type = v
		end
	end

	local function SetProperties()
		v[2].Material = Type.Material
		v[2].Color = Type.Color
		v[2].Transparency = Type.Transparency
		v[2].Name = Type.Material.Name
		v[2].Size = v[2].Size + Vector3.new(0, Type.IncreasedHeight, 0)
		v[2].Position = v[2].Position + Vector3.new(0, Type.IncreasedHeight / 2, 0)
	end
	SetProperties()
end

local partsForUnion = {}; --create a array for us to put parts in, example, 2 parts named sand -> ["sand"] = {sandPart1, sandPart2} 
local countForParts = {}; --lets us count so we can actually check if we need to; 
local maxParts = 15; 
for i, v in pairs(workspace:WaitForChild("Map"):GetDescendants()) do 
	if not v:IsA("BasePart") then 
		continue; 
	end 
	
	if not countForParts[v.Name] then 
		countForParts[v.Name] = 0; partsForUnion[v.Name] = {}; 
	end 
	countForParts[v.Name] += 1; 
	table.insert(partsForUnion[v.Name], v); 
end; 

for i, v in pairs(countForParts) do 
	if v > maxParts then 
		for _, parts in pairs(partsForUnion) do
			local firstPart = parts[1]; 
			table.remove(parts,1); 
			firstPart:UnionAsync(parts); 
		end 
	end 
end

end

I added it into my polisher code, does not do anything

image

Cant figure out whats wrong with the code, try playing around with it and maybe you can make it work

Alrighty thanks, if anything clicks let me know.