Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make unions in scripts? (Includes negative parts)

I was looking around for this for a while. So basically, I want to know how to make unions in scripts, and I also want to use this in a possibly future game.

I attempted it with the devforum code but for some reason that actually gives an error. Anyone know how to use them in scripts correctly?

This was the devforum code:

local part = workspace.Part1
local otherParts = {workspace.Part2, workspace.Part3}
 
-- Perform union operation
local newUnion = part:UnionAsync(otherParts)
 
-- Destroy source parts
part:Destroy()
for _, otherPart in pairs(otherParts)
	otherPart:Destroy()
end
 
-- Insert new union into workspace
newUnion.Parent = workspace

(I did add the parts by the way.)

2 comments

0

What did the error say? It could be something as simple as not having a part inside of workspace named "Part1."

0

I did add the parts 1 to 3 like the code had it. The error was: expected 'do' when parsing for loop, got 'otherPart'

2 answers

On line 9 and 10, you put 'otherPart' when you defined your variable as 'otherParts'. Maybe that's the problem?

2 comments

0

I just tested this code straight from devforum and I think that variable is the table?

0

Oh, I think they changed what the variable for parts found is. Usually I would just use "i", but roblox used "otherPart" so that isn't the issue.

It turns out ROBLOX themselves had a mistake I guess. It was actually the table's fault. Thanks for your help everyone!

Fixed:

local part = workspace.Part1
local otherParts = {workspace.Part2, workspace.Part3}

-- Perform union operation
local newUnion = part:UnionAsync(otherParts)

-- Destroy source parts
part:Destroy()
for _, otherPart in pairs(otherParts) do
    otherPart:Destroy()
end

-- Insert new union into workspace
newUnion.Parent = workspace

This discussion is preserved as it was. New answers, comments, and votes are closed.