How could union with a script?

Hi, I wanted to ask how could you union 2 parts together in a script?

So like theres a negate part in replicated storage, Then it goes to workspace and I union it with another part and then that part thats unioned has a hole? (with a script)

1 Like

You could use UnionAsync? I think that would work.

Basically, you would write:

Union = TheNormalPart:UnionAsync(TheNegativePart)

Union.Parent = workspace

Also, when you use UnionAsync, the original parts stay, so you could also add underneath:

TheNormalPart:Destroy()
TheNegativePart:Destroy()

You can read more about it here:
BasePart | Documentation - Roblox Creator Hub https://search.app/nMPmwff48bniUFDz5

Hope this helps! :smile:

2 Likes

Hi i tried this but it keeps giving me the error:

Unable to cast value to Objects

Why do i keep getting this error?

You did not read the documentation that @The_DuckDeveloper linked. BasePart:UnionAsync does not take a single part as its first argument. It instead takes an array of parts:

local union = part:UnionAsync({otherPart})
1 Like

Ah I see, ill read the documentation so i don’t get confused with anymore things

Note: I found out that unioning a negate part with a normal part using UnionAsync will not work, You need to use SubtractAsync