TruWorlds

Instance

Inherits: TruWorldsObject

Instance is the base type for all TruWorlds game objects.

Instances form a hierarchical tree structure part of the DataModel, where each Instance can have one parent and multiple children. Instances can be created, destroyed, and replicated across the network. They also support events for changes in the hierarchy and lifecycle.

Properties

Archivable bool

Whether this Instance or any of its descendants should be included when saving or copying via Clone()

Id Guid

The unique identifier for this Instance.

Locked bool

If true, this instance and all of its descendants cannot be selected in the editor.

Name string

The name of this Instance.

Parent Instance?

The parent of this Instance in the hierarchy.

ScriptData InstanceScriptData
SortIndex ushort

The sort index of this Instance among its siblings. If this Instance has no parent, this value is ignored.

Functions

AttachScript(path: string)

Attaches a script to this instance by its file path. The path should be relative to the root assets directory, e.g. "Scripts/MyScript".

Clone() Returns Instance

Creates a deep clone of this Instance and all its descendants.

Returns: >A new Instance that is a deep clone of this Instance.

local template = world.FindFirstChild("CoinTemplate")
if template:
    local coin = template.Clone()
    coin.Position = new Vector3(0, 5, 0)
    coin.Parent = world
Destroy()

Removes this Instance, and all its descendants, from the DataModel, and locks its parent property.

local part = new Part()
part.Parent = world
wait(5)
part.Destroy()
DestroyAfter(delaySeconds: float)

Schedules this Instance to be destroyed after the specified delay in seconds. This function will error if called multiple times.

delaySeconds
DetachScript(path: string)

Removes a script from this instance by its file path. The path should be relative to the root assets directory, e.g. "Scripts/MyScript".

FindFirstChild(name: string) Returns Instance?
local door = world.FindFirstChild("Door")
if door:
    door.Visible = false
GetChildren() Returns Instance[]

Returns an array of the children of this Instance.

local folder = world.FindFirstChild("Coins")
if folder:
    for child in folder.GetChildren():
        child.Color = new Color3(1, 1, 0)
GetContentsGlobalBoundsBox() Returns BoundsBox?

Gets the global bounding box that encapsulates all DynamicInstance children of this Instance.

Returns: The global bounding box of all DynamicInstance children, or null if there are none.

GetDescendants() Returns Instance[]
GetScriptCount() Returns int
GetScriptPath(index: int) Returns string

Returns the path of the script component at , or an empty string if the script file no longer exists.

IsDescendantOf(ancestor: Instance) Returns bool

Determines if this Instance is a descendant of the specified ancestor Instance.

ancestor
The potential ancestor Instance.

Returns: True if this Instance is a descendant of the ancestor; otherwise, false.

Signals

ChildAdded Instance

Event fired when a child is added to this Instance.

ChildRemoved Instance

Event fired when a child is removed from this Instance.

DescendantAdded Instance

Event fired when a descendant is added to this Instance.

DescendantRemoving Instance

Event fired when a descendant is about to be removed from this Instance.

Destroyed

Event fired when this instance is destroyed.

ParentChanged Instance?

Event fired when the parent of this Instance changes.

Removed

Event fired when this instance is removed from the DataModel.

SortIndexChanged ushort

Event fired when the sort order of this Instance changes.