Instance

Instance : ``

Overview

Instance is the top parent class of all OVERDARE Lua classes.

Description

An instance is an abstract class that represents the elements composing a data model tree. It enables the storage and modification of parent and child relationships within a tree structure, as well as provides the properties necessary to access and differentiate instances. Instances allow for creation, destruction, and replication, and include features that facilitate locating or modifying instances deployed in the world. These features enable comparisons and modifications based on attributes such as tag, class names, instance names, and more.

Properties

Parent

Instance

The parent instance of that instance in the data model tree.

Code Samples

print(Part.Parent)

Archivable

bool

"Archivable" property is to determine whether an instance can be saved, restored, and preserved across gameplay sessions.

Code Samples

//NotWork//

ClassName

string

Represents the Lua Class name of that instance.

Code Samples

local Part = script.Parent
print(Part.ClassName)

Name

string

Represents the name of that instance. The Name property is a user-defined string that identifies the instance within the hierarchy. It can be used to reference and differentiate instances programmatically.

Code Samples

local Part = script.Parent

Part.Name = "NewPart"

Attributes

array

Store additional data or metadata related to the instances, allowing developers to customize and manage Lua attributes with flexibility.

Code Samples

//NotWork//

LuaTags

array

Tags can be used to organize, categorize, filter, and search for instances within the context of Lua scripting.

Code Samples

local Workspace = game:GetService("Workspace")
local Part = Workspace.Part

local Tags = Part:GetTags()
for i = 1, #Tags do
    print(Tags[i])
end

Methods

Clone

This method creates a copy of the instance and its descendants (if any) in the data model tree. The cloned instance will be a separate entity and not linked to the original, but it retains the same properties, attributes, and child instances as the original at the time of cloning.

Parameters

Return

Instance

Code Samples

local Workspace = game:GetService("Workspace")
local Part = Workspace.Part

local NewPart = Part:Clone(Part)
NewPart.Position = Part.Position + Vector3.new(300, 0, 0)
NewPart.Parent = Workspace

LuaDestroy

This method deletes (destroys) the instance from the data model tree. The LuaDestroy method removes the instance and its descendants (if any) from the hierarchy permanently. Note: Once an instance is destroyed, it cannot be recovered.

Parameters

Return

virtual void

Code Samples

local Workspace = game:GetService("Workspace")
local Part = Workspace.Part

Part:Destroy()

FindFirstAncestor

An instance method used to find the first ancestor in the hierarchy by matching its name with the specified InName parameter. This allows developers to traverse up the hierarchy to locate an instance with a specific name.

If no matching ancestor is found, the method returns nil.

Parameters

string InName

Return

Instance

Code Samples

local Part = script.Parent

local Ancestor = Part:FindFirstAncestor("ParentPart")
print(Ancestor)

FindFirstAncestorOfClass

Finds the first ancestor of the instance that matches the specified class name InClassName. This method is useful for traversing up the object hierarchy to locate a specific class type.

Parameters

string InClassName

The first ancestor that matches the specified class name, or nil if no match is found.

Return

Instance

Code Samples

local Part = script.Parent

--wait(1)
local AncestorOfClass = Part:FindFirstAncestorOfClass("Part")
print(AncestorOfClass)

FindFirstAncestorWhichIsA

Checks if the current instance is a descendant of another instance.

Parameters

string InClassName

The class name to check against

Return

Instance

Code Samples

local Part = script.Parent

local AncestorWhichIsA = Part:FindFirstAncestorWhichIsA("Instance")
print(AncestorWhichIsA)

FindFirstChild

Finds the first child of the instance that matches the given name InName. If the recursive parameter is set to true, the method searches through all descendants of the instance. If no matching child is found, the method returns nil.

Parameters

string InName

bool recursive

Return

Instance

Code Samples

local Workspace = game:GetService("Workspace")

local Part = Workspace:FindFirstChild("Part")
print(Part)

FindFirstChildOfClass

This method retrieves the first child of a given instance that matches the specified class name. If the bRecursive parameter is set to true, the method searches all descendants of the instance to find a matching child. Returns the child instance if found; otherwise, it returns nil.

Parameters

string InClassName

bool bRecursive

Return

Instance

Code Samples

local Workspace = game:GetService("Workspace")

local Part = Workspace:FindFirstChildOfClass("Part")
print(Part)

GetAttribute

Query the value of an attribute with a specific name.

Parameters

string attribute

Return

Value

Code Samples

local AttributeName = "Number"
local SetValue = 1
Part:SetAttribute(AttributeName, SetValue)

local GetValue = Part:GetAttribute(AttributeName)
print(GetValue)

GetAttributes

Returns all attributes.

Parameters

Return

Value

Code Samples

Part:SetAttribute("Number", 1)
Part:SetAttribute("Text", "Hello")

local AttributeList = Part:GetAttributes()
for attributeName, attributeValue in pairs(AttributeList) do
    print(attributeName, " : ", attributeValue)
end

GetChildren

The GetChildren method retrieves an array containing all direct children of the instance. This is useful for accessing immediate child objects without including descendants beyond the top level.

Parameters

Return

array

Code Samples

local Workspace = game:GetService("Workspace")

local Children = Workspace:GetChildren() 
for _, child in ipairs(Children) do
    print(child.Name)
end

GetDescendants

The GetDescendants method retrieves an array containing all descendant objects of the instance, including both direct children and nested descendants at all levels.

Parameters

Return

array

Code Samples

local Workspace = game:GetService("Workspace")

local Descendants = Workspace:GetDescendants()
for _, descendant in ipairs(Descendants) do
    print(descendant.Name)
end

IsDescendantOf

The IsDescendantOf method checks if the current instance is a descendant of the specified ancestor instance.

Parameters

Instance InAncestor

Return

bool

Code Samples

local Part = script.Parent
local IsDescendantOf = script:IsDescendantOf(Part)

print(IsDescendantOf)

LuaIsA

IsA method checks if an object is of a specified class name in Lua.

Parameters

string InClassName

Return

bool

Code Samples

if Part:IsA("Part") then
    print("Part")
else
    
end

SetAttribute

Sets the value of an attribute with a specific key in it; if no attribute has that key, create and save a pair.

Parameters

string attribute

Value value

Return

void

Code Samples

local AttributeName = "Number"
local SetValue = 1
Part:SetAttribute(AttributeName, SetValue)

WaitForChild

The WaitForChild method is used to pause the execution of the script until the specified child instance with the given name is found within the parent instance. This is especially useful in situations where you need to ensure that certain objects are loaded and available before proceeding with the rest of the script. An optional timeout period can also be specified to stop waiting after the given duration.

Parameters

string InChildName

number InTimeOut

Return

Instance

Code Samples

local Workspace = game:GetService("Workspace")

local Part = Workspace:WaitForChild("Part")
print(Part)

AddTag

The AddTag method appends or adds a tag to an Instance.

Parameters

FName tag

Return

void

Code Samples

Part:AddTag("SomeTag")

RemoveTag

Removes a specified tag from an object .

Parameters

FName tag

Return

void

Code Samples

Part:RemoveTag("SomeTag")

HasTag

The HasTag method checks if an object has a specific tag.

Parameters

FName tag

Return

bool

Code Samples

if Part:HasTag("SomeTag") then
    
else
    
end

GetTags

The GetTags method retrieves a list of all the tags currently applied to an instance.

Parameters

Return

array

Code Samples

Part:AddTag("SomeTag")

local Tags = Part:GetTags()
for i = 1, #Tags do
    print(Tags[i])
end

Events