ShotInstance

Every object in a program is a ShotInstance: a name, a parent, children, attributes, tags and events, with Roblox's names, so the tree works the way you know.

The project's tree, the services and the handles they give out are all ShotInstances. Methods are called with a colon; a dot call errors at once. Events call back in connect order, each in its own thread. Destroy clears the Parent and locks it, destroys the descendants and cuts every connection, while Parent = nil keeps an instance alive. A property hides a child of the same name. typeof gives "userdata", so test classes with IsA.

abstractBase

A base class: you work with its subclasses.

Example

Build and walk a treeShotScript
-- Builds a small tree at run time and uses the members every instance has.
local shop = Instance.new("Folder")
shop.Name = "Shop"
shop.ChildAdded:Connect(function(child : ShotInstance)
	print("added " .. child.Name)
end)

local apple = Instance.new("NumberValue")
apple.Name = "Apple"
apple:SetAttribute("Price", 3)
apple:AddTag("Fruit")
apple.Parent = shop

print(apple:GetFullName() .. " is a " .. apple.ClassName .. ", IsA ShotInstance " .. tostring(apple:IsA("ShotInstance")))
print("Price " .. tostring(apple:GetAttribute("Price")) .. ", tagged Fruit " .. tostring(apple:HasTag("Fruit")))

local copy = shop:Clone()
local copied = copy:FindFirstChild("Apple")
print("the copy's Apple: " .. (if copied then "Price " .. tostring(copied:GetAttribute("Price")) else "missing"))
print("the copy's Parent: " .. tostring(copy.Parent))

shop:Destroy()
print("Apple after Destroy: " .. (if pcall(function() return apple.Name end) then "usable" else "destroyed"))
What it printedOutput
added Apple
Shop.Apple is a NumberValue, IsA ShotInstance true
Price 3, tagged Fruit true
the copy's Apple: Price 3
the copy's Parent: nil
Apple after Destroy: destroyed
The Explorer showing a project's tree four levels deep, with folders, a program, a class and its Types, a Luau module and value objects, beside the Properties of the number value Apple.
A project's object tree

Properties

NameTypeDefaultDescription
ClassNamestring"ShotInstance"
read-only
The name of the instance's class, set when it is made; assigning it errors with "Property is read only".
Namestring"ShotInstance"The instance's name, its class name until you set one; tostring of an instance gives it, and children are found by it.
ParentShotInstance?The instance it sits under, or nil; setting nil keeps it alive, while services, handles and destroyed instances refuse a new Parent.

Methods

NameArgumentsReturnsDescription
AddTag(tag: string)()Adds a tag; tags are a set, so adding one the instance already has changes nothing.
ClearAllChildren()()Destroys every child, skipping children whose Parent is locked, such as the handles a service holds.
Clone()ShotInstanceCopies the instance with its properties, attributes, tags, script source and descendants, Parent nil; services and handles can't be cloned.
Destroy()()Destroys the instance and its descendants: Parent nil and locked, connections cut, waits resumed with nil; a second call does nothing.
FindFirstAncestor(name: string)ShotInstance?The nearest ancestor with that name, walking up from the parent, or nil.
FindFirstAncestorOfClass(className: string)ShotInstance?The nearest ancestor whose class is exactly className, or nil; subclasses don't count here.
FindFirstAncestorWhichIsA(className: string)ShotInstance?The nearest ancestor for which IsA(className) is true, so a base class such as ValueBase matches too, or nil.
FindFirstChild(name: string, recursive: boolean?)ShotInstance?The first child with that name, or nil; with recursive true it also searches every descendant.
FindFirstChildOfClass(className: string)ShotInstance?The first direct child whose class is exactly className, or nil.
FindFirstChildWhichIsA(className: string, recursive: boolean?)ShotInstance?The first child for which IsA(className) is true, or nil; with recursive true it searches every descendant.
GetAttribute(attribute: string)unknown?The attribute's value, or nil when it isn't set; a name other than letters, digits and _ errors.
GetAttributeChangedSignal(attribute: string)ShotSignal<>A signal that fires, passing nothing, each time that one attribute changes.
GetAttributes(){ [string]: unknown }A copy of every attribute by name; changing the table changes nothing on the instance.
GetChildren(){ ShotInstance }The direct children in the order they were parented, as a new table.
GetDescendants(){ ShotInstance }Every instance below this one, depth first: each child, then that child's own descendants.
GetFullName()stringThe names from the top ancestor down to this one, joined by dots, such as MyProject.Settings.Currency.
GetPropertyChangedSignal(property: string)ShotSignal<>A signal that fires, passing nothing, when that property changes; a name that isn't a property errors.
GetTags(){ string }The instance's tags, in the order they were added.
HasTag(tag: string)boolean
IsA(className: string)booleanTrue when the class is className or inherits from it, ShotInstance and Instance included; use it, since typeof gives "userdata".
IsAncestorOf(descendant: ShotInstance)booleanWhether descendant sits somewhere below this instance; an instance is not its own ancestor.
IsDescendantOf(ancestor: ShotInstance)booleanWhether this instance sits somewhere below ancestor; false for the instance itself.
RemoveTag(tag: string)()Removes the tag; removing one the instance doesn't have does nothing.
SetAttribute(attribute: string, value: any)()Sets an attribute, nil removes it; values take Roblox's attribute types, names letters, digits and _ (at most 100, not starting RBX).

Events

NamePassesDescription
AncestryChanged(ShotInstance, ShotInstance?)Fires on the moved instance and on each of its descendants, passing the moved instance and its new parent.
AttributeChanged(string)Fires with the attribute's name when SetAttribute changes it, removal by nil included; setting the same value again fires nothing.
Changed(any)Fires with the changed property's name; on a value object it fires with the new Value instead, and only when Value changes.
ChildAdded(ShotInstance)Fires with the child once it is parented here, after the old parent's ChildRemoved has fired.
ChildRemoved(ShotInstance)Fires with the child after it left this instance, through a new Parent, Parent = nil or Destroy.
Destroying()Fires as Destroy begins: its callbacks start before the children are destroyed and the Parent is cleared.

Subclasses