Want a special badge and 30 bux? Make some PolyWorld! Content and post it in the Creations forum!
Dark mode is incomplete! Please report any issues to the Discord.

Instance

LocalScripts Scripts Not creatable Parent type

Instances are a parent-type class in PolyWorld that contains many types of Classes, mainly Parts.


Overview

Properties

Methods

Events


API

Properties

Name

Name : string
The name of the Instance.
You can both read and write to or from this property.

name

name deprecated : string
Identical to Name.
No longer recommended for use.

ClassName

ClassName readonly : string
The name of the Instance's class, such as Part or Connector.
You can only read from this property, but not write to it.

Parent

Parent : Instance
The parent instance of another Instance.

parent

parent deprecated : Instance
Identical to Parent.
No longer recommended for use.

Methods

Destroy

Destroy() : void
Destroys the Instance, making it no longer able to be used.
Refrences to the Instance will become nil.

Clone

Clone() : Instance?
Creates a clone of the Instance with all the same properties.
This will fail if the instance should not be cloned, such as a Character.

DestroyChildren

DestroyChildren(limit: int?) : void
Destroys all children of the Instance.
If limit is provided, it will stop after destroying limit Children.

GetChildren

GetChildren(limit: int?) : List of Instances
Provides a list of every Child within the Instance.
If limit is provided, it will stop providing parts after providing limit Children.

FindFirstChild

FindFirstChild(name: string?) : Instance?
Finds the first child inside an Instance.
if name is provided, it will search only for children with Name as name.

FindFirstChildWithClass

FindFirstChildWithClass(name: string?, classname: string) : Instance?
Finds the first child inside an Instance, with it's ClassName equal to classname.
if name is provided, it will search only for children with Name as name.

FindFirstChildOfClass

FindFirstChildOfClass(name: string?, classname: string) : Instance?
Alias of FindFirstChildWithClass.

local part = model:FindFirstChildOfClass("Part")

FindByName and GetPlayers currently also exist on every Instance because they share Workspace's method table.
Prefer `Workspace:FindByName` and `Players:GetPlayers`.

IsType

IsType(typeName: string) : bool
Returns true if this Instance's ClassName matches typeName, or if it inherits that type.
For example, a Part returns true for both "Part" and "Instance".

if child:IsType("Part") then
    child.Anchored = true
end

WaitForChild

WaitForChild(name: string, timeout: number?) : Instance
Yields until a child with the given Name exists, then returns it.
timeout is optional seconds. Default is 5.
Errors if the child is not found before the timeout.

Events

Events are Event objects. Listen with `Connect`, `Once`, or `Wait`.

instance.ChildAdded:Connect(function(child)
    print(child.Name, "was added")
end)

BeingDestroyed

BeingDestroyed : Event ()
Triggers when the Instance is about to be destroyed. It will wait for this event to finish before destroying.

ChildAdded

ChildAdded : Event (child: Instance)
Triggers when an Instance is added to the children of the target Instance.

ChildChanged

ChildChanged : Event (child: Instance, fieldName: string, fieldVal: any)
Triggers when a child of the Instance has a change in it's properties.

ChildRemoving

ChildRemoving : Event (child: Instance, destroying: bool)
Triggers when a child of the Instance is being destroyed or being removed from the Instance's children.

DescendantAdded

DescendantAdded : Event (descendant: Instance)
Triggers when an Instance is added to the descendants of the target Instance.

DescendantChanged

DescendantChanged : Event (child: Instance, fieldName: string, fieldVal: any)
Triggers when a descendant of the Instance has a change in it's properties.

DescendantRemoving

DescendantRemoving : Event (descendant: Instance, destroying: bool)
Triggers when a descendant of the Instance is being destroyed or being removed from the Instance's descendants.