Skip to main content

Instance

Not Creatable Abstract

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


Summary

Properties

Methods

Events


Properties

CanReparent

Instance.CanReparent: bool

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


ClassName

Instance.ClassName: string

Returns the name of the class.


Item

Instance.Item: Instance

Specifies the name of an instance.


Name

Instance.Name: string

Specifies the name of an instance.


Parent

Instance.Parent: Instance

Specifies the parent instance of an instance.


Shared

Instance.Shared: array

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

ClientSpawned

Instance.ClientSpawned: bool

Returns whether or not the instance was spawned by the client.


Methods

New

Instance:New(typeOfInstance: string): Instance

Parameters:

ParameterTypeDefaultDescription
typeOfInstancestring-

Create a new instance.

Example

local newInstance = Instance.New("Part")

New

Instance:New(typeOfInstance: string, parent: Instance): Instance

Parameters:

ParameterTypeDefaultDescription
typeOfInstancestring-
parentInstance-

Create a new instance.

Example

local newInstance = Instance.New("Part", game["Environment"])

Clone

Instance:Clone()

Clones the instance


Destroy

Instance:Destroy()

Destroys the instance (same as Delete method)


Delete

Instance:Delete()

Deletes the instance (same as Destroy method)


GetParent:Instance

Instance:GetParent:Instance()

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


SetParent

Instance:SetParent(newParent: Instance)

Parameters:

ParameterTypeDefaultDescription
newParentInstance-

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


IsA

Instance:IsA(className: string): bool

Parameters:

ParameterTypeDefaultDescription
classNamestring-

Returns whether or not the instance is the specified class.


IsDescendantOf

Instance:IsDescendantOf(other: Instance): bool

Parameters:

ParameterTypeDefaultDescription
otherInstance-

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


FindChild

Instance:FindChild(name: string): Instance

Parameters:

ParameterTypeDefaultDescription
namestring-

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


FindChildByClass

Instance:FindChildByClass(className: string): Instance

Parameters:

ParameterTypeDefaultDescription
classNamestring-

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


GetChildren:Instance

Instance:GetChildren:Instance[]()

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


GetChildrenOfClass

Instance:GetChildrenOfClass(className: string): Instance[]

Parameters:

ParameterTypeDefaultDescription
classNamestring-

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


GetBounds

Instance:GetBounds(): Bounds

Returns the bounds of the instance.

Properties


Events

ChildAdded

Instance.ChildAdded(child: Instance)

Parameters:

ParameterTypeDefaultDescription
childInstance-

Fires when a child instance is added.

Example

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

ChildRemoved

Instance.ChildRemoved(child: Instance)

Parameters:

ParameterTypeDefaultDescription
childInstance-

Fires when a child instance is removed.

Example

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

Clicked

Instance.Clicked(player: Player)

Parameters:

ParameterTypeDefaultDescription
playerPlayer-

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

Instance.MouseEnter()

Fires when the mouse enters the instance.

Example

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

MouseExit

Instance.MouseExit()

Fires when the mouse enters the instance.

Example

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

Touched

Instance.Touched(otherPart: Instance)

Parameters:

ParameterTypeDefaultDescription
otherPartInstance-

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

Instance.TouchEnded(otherPart: Instance)

Parameters:

ParameterTypeDefaultDescription
otherPartInstance-

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