Instance

Inherits Object

Instance is the fundamental building block of the game's object tree. It provides parent-child relationships, attributes, and events for tracking changes in the hierarchy. All game objects inherit from Instance.

Properties

Parent

Instance | nil

The parent of this instance in the hierarchy

Archivable

bool

When true, the instance can be saved and cloned

Name

string

The name of this instance

ClassName

string Read-only Inherited from Object

The name of this object's class

Methods

AddTag(tag: string)

void

Adds a tag to this instance

Parameters:

  • tag string

HasTag(tag: string)

bool

Checks if this instance has a specific tag

Parameters:

  • tag string

RemoveTag(tag: string)

void

Removes a tag from this instance

Parameters:

  • tag string

GetAttribute(attribute: string)

Attribute | nil

Gets the value of an attribute

Parameters:

  • attribute string

GetAttributes()

table

Returns a table of all attributes

SetAttribute(attribute: string, value: Attribute)

void

Sets the value of an attribute

Parameters:

  • attribute string
  • value Attribute
part:SetAttribute("Health", 100)
local health = part:GetAttribute("Health")

FindFirstAncestor(name: string)

Instance | nil

Finds the first ancestor with the specified name

Parameters:

  • name string

FindFirstAncestorOfClass(className: string)

Instance | nil

Finds the first ancestor of the specified class

Parameters:

  • className string

FindFirstAncestorWhichIsA(className: string)

Instance | nil

Finds the first ancestor that is an instance of the class

Parameters:

  • className string

FindFirstChild(name: string)

Instance | nil

Finds the first direct child with the specified name

Parameters:

  • name string

FindFirstChildOfClass(name: string)

Instance | nil

Finds the first direct child of the specified class

Parameters:

  • name string

FindFirstChildWhichIsA(name: string)

Instance | nil

Finds the first child that is an instance of the class

Parameters:

  • name string

FindFirstDescendant(name: string)

Instance | nil

Finds the first descendant with the specified name

Parameters:

  • name string

GetChildren()

table

Returns an array of all direct children

for _, child in ipairs(workspace:GetChildren()) do
print(child.Name)
end

GetDescendants()

table

Returns an array of all descendants

IsAncestorOf(descendant: Instance)

bool

Checks if this instance is an ancestor of the target

Parameters:

  • descendant Instance

IsDescendantOf(ancestor: Instance)

bool

Checks if this instance is a descendant of the target

Parameters:

  • ancestor Instance

ClearAllChildren()

void

Removes and destroys all children

Destroy()

void

Permanently destroys this instance and all descendants

SetParent(newParent: Instance)

void

Sets the parent of this instance

Parameters:

  • newParent Instance - | nil

AddChild(child: Instance)

void

Adds a child to this instance

Parameters:

  • child Instance

RemoveChild(child: Instance)

void

Removes a child from this instance

Parameters:

  • child Instance

IsA(className: string)

bool Inherited from Object

Checks if this object is an instance of the specified class

Parameters:

  • className string

FirePropertyChanged(propertyName: string)

void Inherited from Object

Triggers the Changed event for a specific property

Parameters:

  • propertyName string

Events

AncestryChanged

Event(child: Instance, parent: Instance)

Fires when the instance's ancestry changes

AttributeChanged

Event(attributeName: string)

Fires when an attribute is changed

ChildAdded

Event(child: Instance)

Fires when a child is added to this instance

ChildRemoved

Event(child: Instance)

Fires when a child is removed from this instance

DescendantAdded

Event(descendant: Instance)

Fires when a descendant is added anywhere in the tree

DescendantRemoving

Event(descendant: Instance)

Fires when a descendant is about to be removed

Destroying

Event()

Fires when this instance is being destroyed

Changed

Event(propertyName: string) Inherited from Object

Fires when a property of this object changes

part.Changed:Connect(function(property)
print("Property changed:", property)
end)