Negative part turns to positive part when unioning with script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a hole in a wall with a script.
  2. What is the issue? Include screenshots / videos if possible!
    Whenever I try to union negative parts and a normal part in roblox studio using a script, the negative parts turn positive. Here’s a clip:
    example video for devforum - YouTube
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I looked on the dev forum, nothing.
I have tried to create the negative parts using a script, but when I did that it gave me error -25 when I tried to union them

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- Code I used for the script
-- // Variables
local negativeModel = workspace.Negatives
local negativeParts = {}
local mainPart = workspace.UnionPart
-- // Add parts to table
script.Parent.ClickDetector.MouseClick:Connect(function()
	for v, i in pairs(negativeModel:GetChildren()) do
	
			table.insert(negativeParts, #negativeParts + 1, i)
		
		
	end
	-- // Script
	
	local union = mainPart:UnionAsync(negativeParts)
	union.Parent = workspace
	union.Name = "UnionedPart"
	mainPart:Remove()
	union.Anchored = true
	table.clear(negativeParts)
	for v, i in pairs(negativeModel:GetChildren()) do
			i:Remove()
	end
end)

If you know how to fix that, please reply.

When creating a union you have 1 main part, which you used correctly after that you are able to chose to negate (normal) parts/unions from it (they do not have to be negated first).

After making the decision if you wish to remove parts from the union or add you will
either use:

Part:UnionAsync(otherParts) 

To union it together or to substract parts from it like so:

Part:SubtractAsync(otherParts)

In your case you used :UnionAsync with negated parts, but instead you should just use :SubtractAsync with normal parts.

Read more here:

Addition:
Instead of doing the following:

for v, i in pairs(negativeModel:GetChildren()) do
	table.insert(negativeParts, #negativeParts + 1, i)
end

You could just do:

local negativeParts = negativeModel:GetChildren()

As it gives the same result, an array with all the children of the “negativeModel”.

1 Like

I tried it and it worked. Thank you for your help!