Instance
Instance is the base class of all classes. Every class derives from it and has all properties, events and functions Instance has.
Summary
Properties
CanReparent:boolClassName:stringItem:InstanceName:stringParent:InstanceShared:arrayClientSpawned:bool
Methods
New:InstanceNew:InstanceClone:voidDestroy:voidDelete:voidGetParent:Instance:voidSetParent:voidIsA:boolIsDescendantOf:boolFindChild:InstanceFindChildByClass:InstanceGetChildren:Instance[]:voidGetChildrenOfClass:Instance[]GetBounds:Bounds
Events
ChildAdded:voidChildRemoved:voidClicked:voidMouseEnter:voidMouseExit:voidTouched:voidTouchEnded:void
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.
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
typeOfInstance | string | - |
Create a new instance.
Example
local newInstance = Instance.New("Part")
New
Instance:New(typeOfInstance: string, parent: Instance): Instance
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
typeOfInstance | string | - | |
parent | Instance | - |
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
newParent | Instance | - |
Sets the parent of the instance (same as setting the .Parent property)
IsA
Instance:IsA(className: string): bool
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
className | string | - |
Returns whether or not the instance is the specified class.
IsDescendantOf
Instance:IsDescendantOf(other: Instance): bool
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
other | Instance | - |
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | - |
Attempts to find the first child instance with the specified name (nil if not found).
FindChildByClass
Instance:FindChildByClass(className: string): Instance
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
className | string | - |
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
className | string | - |
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
child | Instance | - |
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
child | Instance | - |
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
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
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:
| Parameter | Type | Default | Description |
|---|---|---|---|
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)
TouchEnded
Instance.TouchEnded(otherPart: Instance)
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
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)