Instance (Data Structure)

(Redirected from Instance.new)
< Global namespace | Roblox namespace

In Roblox, an Instance is an object in a Roblox game. Roblox's namespace has a data-type 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.

Constructors[edit]

Instance Instance.new(string className)

Description:
Returns a new object of the class named by className, if it can be created.

Instance Instance.new(string className, Instance parent)

Description:
Returns a new object of the class named by className, and sets it's Parent property to parent.

Notes:

  • Due to how Roblox handles property listeners, setting properties after parenting an object can cause performance issues. It would be in your best interest to avoid using this method. For more information, see this thread

Creating Instances[edit]

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.

Optionally, you can pass a second argument, referring to what Object Icon.pngInstance the new instance should be parented to, but this is not recommended.

local part = Instance.new("Part")
part.Anchored = true
part.BrickColor = BrickColor.new("Really red")
part.Name = "Red Part"
part.Parent = workspace
 
local hint = Instance.new("Hint")
hint.Text = "The name of the part we created is: " .. part.Name
hint.Parent = workspace

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.