SubstractAsync not substracting

This script should make an hole in the wall.
But sometimes it works and sometimes it breaks (no error)

function CreateWall(edgepart:BasePart,doors,color:Color3,size:Vector3)
	local Wall=Instance.new("Part")
	Wall.Anchored=true
	Wall.Size=Vector3.new(size.X,8.5,size.Z)
	Wall.Material=Enum.Material.Concrete
	Wall.Color=color
	Wall.CFrame=edgepart.CFrame
	Wall.Position+=Vector3.new(0,8.5/2,0)
	
	for i,v:Model in doors do
		local Negate=Instance.new("Part")
		Negate.Anchored=true
		Negate.Size=v:GetExtentsSize()
		Negate.Position=v:GetBoundingBox().Position
		Negate.Rotation=v.PrimaryPart.Orientation
		Negate.Parent=workspace
		local temp=Wall:SubtractAsync({Negate},Enum.CollisionFidelity.PreciseConvexDecomposition)
		Wall:Destroy()
		--temp:Clone().Parent=workspace
		Wall=temp:Clone()
		Negate:Destroy()
		temp:Destroy()
		
	end
	--Wall:Clone().Parent=workspace
	return Wall
end

Please help me there was an similar topic but it didnt help me
and my spelling garbage

1 Like

Try this and see if it works:

function CreateWall(edgepart: BasePart, doors: {Model}, color: Color3, size: Vector3)
    local Wall = Instance.new("Part")
    Wall.Anchored = true
    Wall.Size = Vector3.new(size.X, 8.5, size.Z)
    Wall.Material = Enum.Material.Concrete
    Wall.Color = color
    Wall.CFrame = edgepart.CFrame
    Wall.Position = Wall.Position + Vector3.new(0, 8.5 / 2, 0)

    for i, door in ipairs(doors) do
        local Negate = Instance.new("Part")
        Negate.Anchored = true
        Negate.Size = door:GetExtentsSize()
        Negate.CFrame = door:GetBoundingBox()
        Negate.Parent = workspace
        local temp = Wall:Subtract(Negate)
        Wall:Destroy()
        Wall = temp
        Negate:Destroy()
    end

    Wall.Parent = workspace
    return Wall
end

it didnt seem to work. The problem is very weird

Try this, and see if it works. I’m really not sure what is causing the wall to sometimes subtract, and other times, not to.

function CreateWall(edgepart: BasePart, doors: {Model}, color: Color3, size: Vector3)
    local Wall = Instance.new("Part")
    Wall.Anchored = true
    Wall.Size = Vector3.new(size.X, 8.5, size.Z)
    Wall.Material = Enum.Material.Concrete
    Wall.Color = color
    Wall.CFrame = edgepart.CFrame
    Wall.Position = edgepart.Position + Vector3.new(0, 8.5 / 2, 0) -- Adjusted positioning

    for i, door in ipairs(doors) do
        local doorSize = door:GetExtentsSize()
        local doorPosition = door.Position

        local Negate = Instance.new("Part")
        Negate.Anchored = true
        Negate.Size = doorSize
        Negate.Position = doorPosition
        Negate.Parent = workspace

        local temp = Wall:Subtract(Negate)
        Wall:Destroy()
        Wall = temp
        Negate:Destroy()
    end

    Wall.Parent = workspace
    return Wall
end

I just had to substract it an second time and it was fixed. Roblox CSG is just weird and broken.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.