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.

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)

Re-attaches an existing component ref (used by detach-undo to preserve identity).

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 = 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 = 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)

Detaches a specific component by reference. Use this to remove a broken component, which has no live file to identify it by.

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 = Color3(1, 1, 0)
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.