UnionAsync is not available in the for loop

Hello.
I am currently writing code as I would like to Unionize each of my 3000+ models.
I understand how to create a Union by itself, but when I try to loop through it, it does not work at all.
Please tell me what is wrong with my code.

for _,y in pairs(workspace.MainLine:GetDescendants(""))do
	if y.Name == "PartBase" then
		local mainPart = y
		local otherParts = {}
		
		for _,x in pairs(y.Parent:GetDescendants(""))do
			if not x:IsA("BasePart") then continue end
			if x.Material == Enum.Material.Concrete and x.Name == "Part" then
				otherParts[#otherParts + 1] = x
			end
		end
		
		local success, newUnion = pcall(function()
			return mainPart:UnionAsync(otherParts)
		end)

		if success and newUnion then
			newUnion.Parent = mainPart.Parent
			newUnion.CanTouch = false
			newUnion.Name = "TrackUnion"
		end

		mainPart:Destroy()
		for _, part in otherParts do
			part:Destroy()
		end
	end
end

This script finds a part named “PartBase” in the folder “MainLine” and creates a union based on it.
The parent of the created union is set to the parent of the base part.

Self resolved. It seems to take a fair amount of time to generate a union.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.