Skip to content

Instance

Not newable

This object cannot be created by scripts using Instance.New().

Instance is the base class of all classes. Every class derives from it and has all properties, events and functions Instance has.

Abstract Object

This object exists only to serve as a foundation for other objects. It cannot be accessed directly, but its properties are documented below.

Additionally, it cannot be created in the creator menu or with Instance.New().

Events

ChildAdded

Parameters: child [ Instance ]

Fires when a child instance is added.

Example

game["Environment"].ChildAdded:Connect(function (child)
    print(child.Name .. " was added")
end)

ChildRemoved

Parameters: child [ Instance ]

Fires when a child instance is removed.

Example

game["Environment"].ChildRemoved:Connect(function (child)
    print(child.Name .. " was removed")
end)

Clicked

Parameters: player [ Player ]

Fires when the instance is clicked by a player.

Example

game["Environment"]["Part"].Clicked:Connect(function (player)
    print(player.Name .. " clicked on this part!")
end)

MouseEnter

Fires when the mouse enters the instance.

Example

part.MouseEnter:Connect(function()
    part.Color = Color.New(1, 0, 0)
end)

MouseExit

Fires when the mouse enters the instance.

Example

part.MouseExit:Connect(function()
    part.Color = Color.New(0, 1, 0)
end)

Touched

Parameters: otherPart [ Instance ]

Fires when the instance was touched by another instance. If you are trying to detect a player touching the instance, make sure to check with otherPart:IsA('Player') before continuing the anonymous function. Also, it's recommended to apply a debounce variable to the event.

Example

game["Environment"]["Part"].Touched:Connect(function (otherPart)
    print(otherPart.Name .. " touched this part!")
end)

There must be an active collider on the instance for this event to trigger ( Part, Player, etc.)

TouchEnded

Parameters: otherPart [ Instance ]

Fires when the instance is no longer being touched by another instance.

Example

game["Environment"]["Part"].TouchEnded:Connect(function (otherPart)
    print(otherPart.Name .. " stopped touching this part!")
end)

There must be an active collider on the instance for this event to trigger ( Part, Player, etc.)

Methods

New → Instance

Parameters: typeOfInstance

Create a new instance.

Clone → void

Clones the instance

Destroy → void

Destroys the instance (same as Delete method)

Delete → void

Deletes the instance (same as Destroy method)

GetParent → Instance

Returns the parent of the instance (same as accessing the .Parent property).

SetParent → void

Parameters: newParent [ Instance ]

Sets the parent of the instance (same as setting the .Parent property)

IsA → boolean

Parameters: className [ string ]

Returns whether or not the instance is the specified class.

IsDescendantOf → boolean

Parameters: other [ Instance ]

Returns whether or not the instance is a descendant (child, child of child, etc) of the specified instance.

FindChild → Instance

Parameters: name [ string ]

Attempts to find the first child instance with the specified name (nil if not found).

FindChildByClass → Instance

Parameters: className [ string ]

Attempts to find the first child instance with the specified class (nil if not found).

GetChildren → Instance[]

Returns an array of all the children instances parented to the instance.

GetChildrenOfClass → Instance[]

Parameters: className [ string ]

Returns an array of all the children instances with the specified class.

Properties

CanReparent : boolean

Returns whether this instance can be reparented/deleted or not.

ClassName : string

Returns the name of the class.

Item : Instance

Specifies the name of an instance.

Name : string

Specifies the name of an instance.

Parent : Instance

Specifies the parent instance of an instance.

Shared : []

An empty table you can use to hold metadata about anything on any object or player you want.

Shared doesn't sync from the client to the server, or from the server to the client.

Example

-- Script 1
local players = game.Players.GetChildren()
local lucky = players[math.random(1, #players)]

lucky.Shared.IsZombie = true
-- Script 2
local killBrick = game.Environment["Kill Brick"]

killBrick.Touched:Connect(function(hit)
    if hit.IsA("Player") then
        if hit.Shared.IsZombie then
            print("YOU CAN'T KILL ME, I'M ALREADY DEAD!")
        else
            hit.Health = 0
        end
    end
end