PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

SubtractAsync

This is a server-only function that uses CSG to subtract the geometry of a table of BasePart|BaseParts from the calling BasePart. It returns a parentless UnionOperation named Union with the following specs:

  • The faces of the returned UnionOperation inherit the colors of the original parts’ faces.
  • The PartOperation/UsePartColor|UsePartColor property will be false.
  • The PartOperation/CollisionFidelity|CollisionFidelity will match the provided enum (or default).
  • The returned UnionOperation inherits the following properties from the part that this function was called from: BasePart/Color|Color, BasePart/Material|Material, BasePart/Reflectance|Reflectance, BasePart/Transparency|Transparency, BasePart/Anchored|Anchored, BasePart/CanCollide|CanCollide, BasePart/Elasticity|Elasticity, BasePart/Friction|Friction, and BasePart/CustomPhysicalProperties|CustomPhysicalProperties.

See the Articles/in game solid modeling|In-Game Solid Modeling article for more information.

Potential Errors

This function raises an error under the following conditions:

  • If the resulting union is empty due to subtractions.
  • When called by the client (this cannot be called by a LocalScript).
  • If any of the objects involved are not supported by CSG (only BasePart|BaseParts are supported, not Terrain or meshes).
  • If the result could not be computed with less than 5000 triangles.
  • Some other CSG problem occurred while attempting to union.

Parameters

Name Type Default Description

The objects taking part in the subtraction

Default
Automatic

Returns

Return Type Summary

The resulting union from the subtraction operation


Code Samples


Basic In-Game Subtract Operation

This example assumes there are three parts named Part1, Part2, and Part3 in the Workspace. It creates a union by subtracting Part2 and Part3 from Part1, destroys the original parts, and inserts the resulting UnionOperation.

local part = workspace.Part1
local otherParts = {workspace.Part2, workspace.Part3}

-- Perform subtract operation
local newUnion = part:SubtractAsync(otherParts)

-- Destroy source parts
part:Destroy()
for _, otherPart in pairs(otherParts)
	otherPart:Destroy()
end

-- Insert new union into workspace
newUnion.Parent = workspace