Instance: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Ozzypig
>Ozzypig
Line 6: Line 6:
In ROBLOX, an Instance is an object in a ROBLOX game. ROBLOX Lua has a global table called '''Instance''' for changing how objects in the game behave. The Instance table offers several functions in order to create/manipulate ROBLOX created objects. It is best known for the '''Instance.new()''' function.
In ROBLOX, an Instance is an object in a ROBLOX game. ROBLOX Lua has a global table called '''Instance''' for changing how objects in the game behave. The Instance table offers several functions in order to create/manipulate ROBLOX created objects. It is best known for the '''Instance.new()''' function.


==Creating Objects==
==Creating Instances==


Creating objects is very simple, you can find a list of objects in the [[Class_reference|Class Reference]] section of the Wiki. You must pass in the name of the object, and it will return that object.
Creating new objects is simpler than one would guess. You can find a list of object types (called '''classes''') in the [[Class_reference|Class Reference]]. To create a new Instance, you use the '''Instance.new()''' function and pass one argument - a string that refers to what class you wish to make.
   
   
{{CodeExample}}
{{CodeExample}}
Line 20: Line 20:


{{LeftNoticeStart}}
{{LeftNoticeStart}}
By default, all objects are parented to nil. If you have an object such as Part that is rendered, remember to parent it to the Workspace in order for it to be rendered.
By default, objects created with '''Instance.new()''' retain their default properties (such as new bricks being 2 by 4 studs large). Because of this, the Parent property of created objects is '''nil''' and must be set for the object to be functional in the game.


You can pass a second argument to Instance.new to parent the object to it:
You can pass a second argument to Instance.new to set the Parent of the object created:


{{Example|
{{Example|

Revision as of 13:42, 24 December 2010

Instance

In ROBLOX, an Instance is an object in a ROBLOX game. ROBLOX Lua has a global table called Instance for changing how objects in the game behave. The Instance table offers several functions in order to create/manipulate ROBLOX created objects. It is best known for the Instance.new() function.

Creating Instances

Creating new objects is simpler than one would guess. You can find a list of object types (called classes) in the Class Reference. To create a new Instance, you use the Instance.new() function and pass one argument - a string that refers to what class you wish to make.

Template:CodeExample print(Instance.new("Part"))

Will result in: Template:CodeExample Part

By default, objects created with Instance.new() retain their default properties (such as new bricks being 2 by 4 studs large). Because of this, the Parent property of created objects is nil and must be set for the object to be functional in the game.

You can pass a second argument to Instance.new to set the Parent of the object created:

Example
Instance.new("Part", workspace)

Creates a Part and sets its parent to Workspace.

Functions

Function Description
Instance.new(val[, parent]) Returns a new object of the class named by val. The parent argument is optional; if it is supplied the object will be parented to it.
Instance.Lock(val, player) Sets a network enabled mutex for object val targeted at player.
Instance.Unlock(val) Removes the network enabled mutex for object val.