Instance (Table)
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.
print(Instance.new("Part"))
Will result in:
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:
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. |