The Instance class is the base class of the object system. All other classes inherit, either directly or indirectly, from this class and Instance itself inherits from <<<ROOT>>>. The members that are common to all classes belong to the Instance class, which is why many of the most important and most used members belong to this class.

Contents

Properties

Pubfield.gif bool Archivable

Determines whether or not an Instance can be saved when the game closes/attempts to save the game. Note: this only applies to games that use Data Persistence, or SavePlaceAsync.

  • Category: Behavior.
  • Serialization: cannot load or save.

Pubfield.gif string ClassName [ReadOnly] [NotReplicated]

The string name of this Instance's most derived class.

  • Category: Data.
  • Serialization: cannot load or save.

Protfield.gif int DataCost [Hidden] [ReadOnly] [NotReplicated] [Deprecated]

  • Category: Data.
  • Read security: LocalUserSecurity.
  • Write security: LocalUserSecurity.
  • Serialization: cannot load or save.

Pubfield.gif string Name

The name of the instance. Used to access it in the game hierarchy. All class's default name is the ClassName, with the exceptions of ExplorerImageIndex 83.pngSunRaysEffect, ExplorerImageIndex 4.pngNumberValue, ExplorerImageIndex 4.pngBoolValue, ExplorerImageIndex 4.pngStringValue, ExplorerImageIndex 4.pngIntValue, ExplorerImageIndex 4.pngIntConstrainedValue, ExplorerImageIndex 4.pngVector3Value, and ExplorerImageIndex 4.pngCFrameValue.

  • Category: Data.
  • Serialization: can save and load.

Pubfield.gif Instance Parent [NotReplicated]

The Instance that is directly above this Instance in the tree.

  • Category: Data.
  • Serialization: can load only.

Protfield.gif bool RobloxLocked [Hidden]

If this property is true, only scripts with the Plugin permission will be able to index signals and children of the object, set its properties or assign its callbacks, call yielding functions of the object, change the parent of the object's children, or create objects with the object as the parent using Instance.new(class, parent). Furthermore, scripts that do not have this permission will not be able to call non-yielding functions of the object unless it is not a descendant of CoreGui.

This property is used, among other things, for GUI objects created by CoreScripts.

  • Category: Data.
  • Read security: PluginSecurity.
  • Write security: PluginSecurity.
  • Serialization: cannot load or save.

Protfield.gif int64 SourceAssetId [Hidden] [NotReplicated]

  • Category: Data.
  • Read security: RobloxScriptSecurity.
  • Write security: RobloxScriptSecurity.
  • Serialization: can save and load.

Pubfield.gif bool archivable [Hidden] [NotReplicated] [Deprecated]

Deprecated. Use Archivable instead.

  • Category: Behavior.
  • Serialization: can load only.

Pubfield.gif string className [ReadOnly] [NotReplicated] [Deprecated]

  • Category: Data.
  • Serialization: cannot load or save.

Functions

Pubmethod.gif void ClearAllChildren()

Calls destroy on all the children of this instance.

local p = Instance.new("Part")
local p2 = Instance.new("Script", p)

print(#p:GetChildren()) --> 1
p:ClearAllChildren()
print(#p:GetChildren()) --> 0

Pubmethod.gif Instance Clone()

Returns a copy of this Object and all its children. The copy's Parent is nil.

Pubmethod.gif void Destroy()

Removes object and all of its children from the object's parent, and parents them to nil, essentially deleting them. This method also prepares the garbage collector to collect it. Disconnects object and all children from open connections. Object and children may not be usable after calling Destroy.

Pubmethod.gif Instance FindFirstAncestor(string name)

Returns the first ancestor with the name of 'name', or nil if none is found.

Pubmethod.gif Instance FindFirstAncestorOfClass(string className)

Similar to FindFirstAncestor, but searches for an instance with the ClassName property equal to 'className' rather than the name property.

Pubmethod.gif Instance FindFirstAncestorWhichIsA(string className)

Similar to FindFirstAncestorOfClass, but also allows abstract classes.

Pubmethod.gif Instance FindFirstChild(string name, bool recursive = false)

Returns the first child of this Instance that matches the first argument 'name'. The second argument 'recursive' is an optional boolean (defaults to false) that will force the call to traverse down thru all of this Instance's descendants until it finds an object with a name that matches the 'name' argument. The function will return nil if no Instance is found.

Pubmethod.gif Instance FindFirstChildOfClass(string className)

Attempts to return the first child of this Instance that has a ClassName of className, or nil if none are found.

Pubmethod.gif Instance FindFirstChildWhichIsA(string className, bool recursive = false)

Similar to FindFirstChildOfClass, but allows abstract classes.

Pubmethod.gif Instance FindFirstDescendant(string name)

Pubmethod.gif Instance GetActor()

Pubmethod.gif Variant GetAttribute(string attribute)

Pubmethod.gif RBXScriptSignal GetAttributeChangedSignal(string attribute)

Pubmethod.gif Dictionary GetAttributes()

Pubmethod.gif Objects GetChildren()

Returns a read-only table of this Object's children.

Protmethod.gif string GetDebugId(int scopeLength = 4) [NotBrowsable]

This function is for internal testing. Don't use in production code.

  • Security: PluginSecurity.

Pubmethod.gif Array GetDescendants() [CustomLuaState]

Returns an array of this object's descendants, including their children, their children's children, and so on.

Pubmethod.gif string GetFullName()

Returns a string that shows the path from the root node (DataModel) to this Instance. This string does not include the root node (DataModel).

Example:

local model = Instance.new("Model")
model.Name = "example"
model.Parent = workspace
local part = Instance.new("Part")
part.Parent = model
print(part:GetFullName()) --> Workspace.example.Part

Pubmethod.gif RBXScriptSignal GetPropertyChangedSignal(string property)

Returns a EventInstance that fires when the given property for this Instance is changed.

Example:

local part = Instance.new("Part")
part.Parent = workspace
local signal = part:GetPropertyChangedSignal("Color")
signal:Connect(function()
    print("New color!")
end)
part.Color = Color3.new(1,0,0) --> New color!

Pubmethod.gif bool IsA(string className) [CustomLuaState]

Returns a boolean if this Instance is of type 'className' or a is a subclass of type 'className'. If 'className' is not a valid class type in ROBLOX, this function will always return false. More info.

local part = Instance.new("Part")
print(part:IsA("BasePart")) --> true

Pubmethod.gif bool IsAncestorOf(Instance descendant)

Returns whether or not this object is an ancestor of descendant.

Pubmethod.gif bool IsDescendantOf(Instance ancestor)

Returns whether or not this object is a descendant of ancestor.

Pubmethod.gif void Remove() [Deprecated]

Deprecated. Use ClearAllChildren() to get rid of all child objects, or Destroy() to invalidate this object and its descendants.

Pubmethod.gif void SetAttribute(string attribute, Variant value)

Pubmethod.gif Instance WaitForChild(string childName, double timeOut) [CustomLuaState] [CanYield]

Yields the script until the object is found. timeOut is an optional parameter. When timeOut seconds is reached, the function will drop out and return nil.

Pubmethod.gif Objects children() [Deprecated]

Use GetChildren() instead.

Pubmethod.gif Instance clone() [Deprecated]

Use Clone() instead.

Pubmethod.gif void destroy() [Deprecated]

Pubmethod.gif Instance findFirstChild(string name, bool recursive = false) [Deprecated]

Use FindFirstChild() instead.

Pubmethod.gif Objects getChildren() [Deprecated]

Use GetChildren() instead.

Pubmethod.gif bool isA(string className) [Deprecated] [CustomLuaState]

Use IsA() instead.

Pubmethod.gif bool isDescendantOf(Instance ancestor) [Deprecated]

Deprecated. Use IsDescendantOf instead.

Pubmethod.gif void remove() [Deprecated]

Use Destroy() instead.

Events

Pubevent.gif AncestryChanged(Instance child, Instance parent)

Fired when any of this object's ancestors change. First argument 'child' is the object whose parent changed. Second argument 'parent' is the first argument's new parent.

Pubevent.gif AttributeChanged(string attribute)

Pubevent.gif Changed(string property)

Fired after a property changes value. The property argument is the name of the property.

Pubevent.gif ChildAdded(Instance child)

Fired when a child is added to this Instance. child is the instance added.

Pubevent.gif ChildRemoved(Instance child)

Fired when a child is about to be removed from this Instance. child is the object being removed.

Pubevent.gif DescendantAdded(Instance descendant)

Fired after an Instance is parented to this object, or any of this object's descendants. The 'descendant' argument is the Instance that is being added.

Pubevent.gif DescendantRemoving(Instance descendant)

Fired after an Instance is unparented from this object, or any of this object's descendants. The 'descendant' argument is the Instance that is being unparented.

Pubevent.gif childAdded(Instance child) [Deprecated]

Deprecated. Use ChildAdded instead.


External links


Community content is available under CC-BY-SA unless otherwise noted.