Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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.)

0
What did the error say? It could be something as simple as not having a part inside of workspace named "Part1." Rinpix 639 — 4y
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' youngmacka123 17 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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

0
I just tested this code straight from devforum and I think that variable is the table? youngmacka123 17 — 4y
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. youngmacka123 17 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question