Wiki Page, Programming School: Lesson 2: Creating Objects

Wiki Page
2017-04-16T15:48:41-06:00

Link to Wiki article: http://wiki.roblox.com/index.php?title=Instance_(Data_Structure)

'Instance' refers to the server instance you are in, meaning it is not worldwide. Technical details that I needn't go into. All you need to know is that 'Instance' is how you create Parts and other objects temporarily without them already existing in game.

'Instance.new' is the function you use to create new Parts and objects in game. It's syntax is like this: 'Instance.new(className)' or (please don't use this much) 'Instance.new(className, parent)'. className should be the name of the type of object you are creating. Like 'Part' or 'Explosion'. Like most things, variables can be used in place of this, but strings are used commonly. All new objects are created in the workspace, unless a parent is specified. The parent can be 'script.Parent'.

Properties of objects created using 'Instance.new' can be set before they are created. Just make it an object as a variable. Example (taken from the ROBLOX wiki):

'local part = Instance.new("Part")

part.Anchored = true

part.BrickColor = BrickColor.new("Really red")

part.Name = "Red Part"

part.Parent = workspace'

! ! ! ! NOTICE ! ! ! !

If FilteringEnabled is on:

Parts created in a normal script are created in game for everyone.

Parts created in a localscript are created only in the current user's game, and does not affect or exist in anyone else's game.

This difference is important and can be useful at times.

Otherwise, it works like normal.