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 | nilThe parent of this instance in the hierarchy
Archivable
boolWhen true, the instance can be saved and cloned
Name
stringThe name of this instance
The name of this object's class
Methods
AddTag(tag: string)
voidAdds a tag to this instance
Parameters:
tagstring
HasTag(tag: string)
boolChecks if this instance has a specific tag
Parameters:
tagstring
RemoveTag(tag: string)
voidRemoves a tag from this instance
Parameters:
tagstring
GetAttribute(attribute: string)
Attribute | nilGets the value of an attribute
Parameters:
attributestring
GetAttributes()
tableReturns a table of all attributes
SetAttribute(attribute: string, value: Attribute)
voidSets the value of an attribute
Parameters:
attributestringvalueAttribute
part:SetAttribute("Health", 100)
local health = part:GetAttribute("Health")
FindFirstAncestor(name: string)
Instance | nilFinds the first ancestor with the specified name
Parameters:
namestring
FindFirstAncestorOfClass(className: string)
Instance | nilFinds the first ancestor of the specified class
Parameters:
classNamestring
FindFirstAncestorWhichIsA(className: string)
Instance | nilFinds the first ancestor that is an instance of the class
Parameters:
classNamestring
FindFirstChild(name: string)
Instance | nilFinds the first direct child with the specified name
Parameters:
namestring
FindFirstChildOfClass(name: string)
Instance | nilFinds the first direct child of the specified class
Parameters:
namestring
FindFirstChildWhichIsA(name: string)
Instance | nilFinds the first child that is an instance of the class
Parameters:
namestring
FindFirstDescendant(name: string)
Instance | nilFinds the first descendant with the specified name
Parameters:
namestring
GetChildren()
tableReturns an array of all direct children
for _, child in ipairs(workspace:GetChildren()) do
print(child.Name)
end
GetDescendants()
tableReturns an array of all descendants
IsAncestorOf(descendant: Instance)
boolChecks if this instance is an ancestor of the target
Parameters:
descendantInstance
IsDescendantOf(ancestor: Instance)
boolChecks if this instance is a descendant of the target
Parameters:
ancestorInstance
ClearAllChildren()
voidRemoves and destroys all children
Destroy()
voidPermanently destroys this instance and all descendants
SetParent(newParent: Instance)
voidSets the parent of this instance
Parameters:
newParentInstance - | nil
Checks if this object is an instance of the specified class
Parameters:
classNamestring
Triggers the Changed event for a specific property
Parameters:
propertyNamestring
Events
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
Fires when a property of this object changes
part.Changed:Connect(function(property)
print("Property changed:", property)
end)