BasePart
Inherits Instance
BasePart provides the foundation for all 3D objects that can exist in the workspace. It handles physics properties like position, rotation, velocity, and collision. All parts inherit from this class and gain access to physical simulation capabilities.
Examples
-- BasePart is abstract, use Part or other subclasses
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = false
Properties
Position
Vector3The 3D position of the part in world space
Rotation
Vector3The rotation angles in degrees (X, Y, Z)
Size
Vector3The dimensions of the part
Velocity
Vector3The current velocity of the part
RotationVelocity
Vector3The angular velocity of the part
Anchored
boolWhen true, the part is not affected by physics
CanCollide
boolWhen true, the part can collide with other parts
CanQuery
boolWhen true, the part can be detected by raycasts
CanTouch
boolWhen true, the part can trigger touch events
Mass
number Read-onlyThe mass of the part calculated from size and material
Color
Color3The color of the part
CastShadow
boolWhen true, the part casts shadows
Transparency
numberThe transparency of the part from 0 (opaque) to 1 (invisible)
The parent of this instance in the hierarchy
When true, the instance can be saved and cloned
The name of this instance
The name of this object's class
Methods
GetMass()
numberReturns the calculated mass of the part
local mass = part:GetMass()
print("Mass:", mass)
Checks if this instance has a specific tag
Parameters:
tagstring
Removes a tag from this instance
Parameters:
tagstring
Gets the value of an attribute
Parameters:
attributestring
Returns a table of all attributes
Sets the value of an attribute
Parameters:
attributestringvalueAttribute
part:SetAttribute("Health", 100)
local health = part:GetAttribute("Health")
Finds the first ancestor with the specified name
Parameters:
namestring
Finds the first ancestor of the specified class
Parameters:
classNamestring
Finds the first ancestor that is an instance of the class
Parameters:
classNamestring
Finds the first direct child with the specified name
Parameters:
namestring
Finds the first direct child of the specified class
Parameters:
namestring
Finds the first child that is an instance of the class
Parameters:
namestring
Finds the first descendant with the specified name
Parameters:
namestring
Returns an array of all direct children
for _, child in ipairs(workspace:GetChildren()) do
print(child.Name)
end
Returns an array of all descendants
Checks if this instance is an ancestor of the target
Parameters:
descendantInstance
Checks if this instance is a descendant of the target
Parameters:
ancestorInstance
Removes and destroys all children
Permanently destroys this instance and all descendants
Sets the parent of this instance
Parameters:
newParentInstance - | nil
Adds a child to this instance
Parameters:
childInstance
Removes a child from this instance
Parameters:
childInstance
Checks if this object is an instance of the specified class
Parameters:
classNamestring
Triggers the Changed event for a specific property
Parameters:
propertyNamestring
Events
Touched
Event(otherPart: BasePart)Fires when another part touches this part
part.Touched:Connect(function(otherPart)
print("Touched by:", otherPart.Name)
end)
TouchEnded
Event(otherPart: BasePart)Fires when another part stops touching this part
Fires when the instance's ancestry changes
Fires when an attribute is changed
Fires when a child is added to this instance
Fires when a child is removed from this instance
Fires when a descendant is added anywhere in the tree
Fires when a descendant is about to be removed
Fires when this instance is being destroyed
Fires when a property of this object changes
part.Changed:Connect(function(property)
print("Property changed:", property)
end)