FANDOM


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.

Properties

Pubfield 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 string ClassName

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

Category: Data.

Serialization: cannot load or save.

Tags: ReadOnly, NotReplicated.

Protfield int DataCost

Category: Data.

Read security: LocalUserSecurity.

Write security: LocalUserSecurity.

Serialization: cannot load or save.

Tags: ReadOnly, NotReplicated, Deprecated.

Pubfield 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 83SunRaysEffect, ExplorerImageIndex 4NumberValue, ExplorerImageIndex 4BoolValue, ExplorerImageIndex 4StringValue, ExplorerImageIndex 4IntValue, ExplorerImageIndex 4IntConstrainedValue, ExplorerImageIndex 4Vector3Value, and ExplorerImageIndex 4CFrameValue.

Category: Data.

Serialization: can save and load.

Pubfield Instance Parent

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

Category: Data.

Serialization: can load only.

Tags: NotReplicated.

Protfield bool RobloxLocked

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.

Pubfield bool archivable

Deprecated. Use Archivable instead.

Category: Behavior.

Serialization: can load only.

Tags: Hidden, NotReplicated, Deprecated.

Pubfield string className

Category: Data.

Serialization: cannot load or save.

Tags: ReadOnly, NotReplicated, Deprecated.

Functions

Pubmethod void ClearAllChildren()

Calls destroy on all the children of this instance.

local p = Instance.new("Part")
local p2 = Instance.new("Script")
p2.Parent = p
 
print(#p:GetChildren()) --> 1
p:ClearAllChildren()print(#p:GetChildren()) --> 0

Pubmethod Instance Clone()

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

Pubmethod 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 Instance FindFirstAncestor(string name)

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

Pubmethod 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 Instance FindFirstAncestorWhichIsA(string className)

Similar to FindFirstAncestorOfClass, but also allows abstract classes.

Pubmethod 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 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 Instance FindFirstChildWhichIsA(string className, bool recursive = false)

Similar to FindFirstChildOfClass, but allows abstract classes.

Pubmethod Objects GetChildren()

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

Protmethod string GetDebugId(int scopeLength = 4)

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

Security: PluginSecurity.

Tags: NotBrowsable.

Pubmethod Array GetDescendants()

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

Tags: CustomLuaState.

Pubmethod 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 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 bool IsA(string className)

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

Tags: CustomLuaState.

Pubmethod bool IsAncestorOf(Instance descendant)

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

Pubmethod bool IsDescendantOf(Instance ancestor)

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

Pubmethod void Remove()

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

Tags: Deprecated.

Pubmethod Instance WaitForChild(string childName, double timeOut)

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.

Tags: CustomLuaState, CanYield.

Pubmethod Objects children()

Use GetChildren() instead.

Tags: Deprecated.

Pubmethod Instance clone()

Use Clone() instead.

Tags: Deprecated.

Pubmethod void destroy()

Tags: Deprecated.

Pubmethod Instance findFirstChild(string name, bool recursive = false)

Use FindFirstChild() instead.

Tags: Deprecated.

Pubmethod Objects getChildren()

Use GetChildren() instead.

Tags: Deprecated.

Pubmethod bool isA(string className)

Use IsA() instead.

Tags: Deprecated, CustomLuaState.

Pubmethod bool isDescendantOf(Instance ancestor)

Deprecated. Use IsDescendantOf instead.

Tags: Deprecated.

Pubmethod void remove()

Use Destroy() instead.

Tags: Deprecated.

Events

Pubevent 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 Changed(string property)

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

Pubevent ChildAdded(Instance child)

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

Pubevent ChildRemoved(Instance child)

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

Pubevent 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 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 childAdded(Instance child)

Deprecated. Use ChildAdded instead.

Tags: Deprecated.


External links


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