Help with unions

  1. What do you want to achieve? Keep it simple and clear!
    Hello! I am a scripting beginner and i was messing around with geometry service!
    I wanted to make a script where parts and wedges are split to give a really cool explosion effect.

  2. What is the issue? Include screenshots / videos if possible!
    but i have a problem with splitting wedges, which being them not disappearing for some reason

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    so far i didnt find any solutions about it so yeah

This is the code: (try this yourself, open a baseplate and insert 2 folders named Debris and Destructibles [put any baseparts in Destructibles folder and press play! it does take some time to load tho])

local Debris = workspace.Debris 
local Destructibles = workspace.Destructibles

local NewPart = Instance.new("Part", script)
NewPart.Name = "Subtracter"
NewPart.Anchored = true; NewPart.CanCollide = false; NewPart.Transparency = .9; NewPart.Color = Color3.fromRGB(255,0,0); NewPart.CanQuery = false

local Physics = game:GetService("PhysicsService")
local CollectionService = game:GetService("CollectionService")
local Geometry = game:GetService("GeometryService")

Physics:RegisterCollisionGroup("Debris")
Physics:RegisterCollisionGroup("Destructibles")
Physics:CollisionGroupSetCollidable("Debris", "Destructibles", false)

function Weld(part, base)
	if part:IsA("BasePart") then
		local wc = Instance.new("WeldConstraint")
		wc.Part0 = base
		wc.Part1 = part
		wc.Parent = base

	elseif part then
		for _,child in pairs(part:GetChildren()) do
			Weld(child, base)
		end
	end
end

local load = 0
for i,b in pairs(Destructibles:GetChildren()) do
	if b:IsA("BasePart") or b:IsA("Part") then
		b.Anchored = true
		b:ClearAllChildren()
		
		local p = b.Position
		local s = b.Size
		local cf = b.CFrame
		local ox,oy,oz = cf:ToOrientation()
		local Corner = p + s/2
		b.Orientation = Vector3.new(0,0,0)
		b.Transparency = .9
		
		local m = Instance.new("Model", Debris)
		local function Update()
			m:ClearAllChildren()
			local function Create(Axis, v)
				local p = v.Position
				local s = v.Size
				local Corner = p + s/2
				
				local Created = {}
				for i=1, math.ceil(s[Axis]/7) do
					local left = s[Axis] - i*7
					local new = v:Clone()
					local function sub(offset, v)
						if v and offset then
							local subtract = script.Subtracter:Clone()
							subtract.Parent = workspace
							subtract.Size = Vector3.new(100, 100, 100)
							local ua = {} ua[Axis] = ((i*7) +offset)
							subtract.Position = Corner - Vector3.new(ua["X"] or s.X/2, ua["Y"] or s.Y/2, ua["Z"] or s.Z/2)
							local options = {
							}
							local parts = {subtract}
							local t = Geometry:SubtractAsync(v, parts, options)
							local replacing = table.unpack(t)
							subtract:Destroy()
							return replacing
						end
					end
					local replacing = sub(50, new)
					if replacing then replacing = sub(-57, replacing) end
					
					if replacing then
						new:Destroy()
						new = replacing
						new.Parent = Debris
						new.Orientation = Vector3.new(0,0,0)
						new.CollisionGroup = "Debris"
						new.UsePartColor = true
						new.Massless = true
						new.Transparency = 0.7
						Weld(new, b)
						if i%40 == 0 then task.wait(.1) print("Welding...") end
						new.Anchored = false
						table.insert(Created, new)
					end
					
				end return Created
			end
			pcall(function()
				local x = Create("Z", b)
				for i,v in pairs(x) do
					local y = Create("Y", v)
					for i,v in pairs(y) do
						local z = Create("X", v)
						for i, v in pairs(z) do
							v.Parent = m
						end
						v:Destroy()
					end
					v:Destroy()
				end
			end)
			
			m:PivotTo(CFrame.new(p) * CFrame.Angles(ox,oy,oz))
		end
		task.spawn(function()
			Update()
		end)
		b.CollisionGroup = "Destructibles"
		b.CanCollide = false
		b.CanQuery = false
	end
	load += 1 if load%50 == 0 then print(load) task.wait() end
end print("Done!")

if you have answers please tell :pray:

I tried to paste the code and add 3 parts to the Destructibles folder, but it doesn’t seem to split them into multiple parts nor explode and Im not getting any errors, am I missing something?
robloxapp-20250105-1651331.wmv (3.0 MB)

oops! i forgot that you need a part in the script, but there i edited the script to include it. use the new version!