How do I create a brick?

From Legacy Roblox Wiki
Revision as of 22:08, 3 November 2008 by >Mindraker (Maybe we should merge this with instance.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Object Creation via Script

It is time to learn how to create different objects via script. Instead of using "Insert > Object.. > Script", a script line can be used. Almost anything and everything can be created via scripts, even a whole new functioning script.

Adding New Objects (Instances)

Now, to add a new object, we need to use the term 'Instance.new'. This term creates a new instance. An instance is a longer term for an object.

Example:

Instance.new("Part").Parent = game.Workspace

So here in this command, we see the term 'Instance.new()'. So now, we state the objects class, which is in this case, "Part". Because whenever you create a new object, its parent is nil (nothing), we have to set it somewhere, so we change its ".Parent" to 'game.Workspace'.

Editing New Objects

In this section, I will be teaching you how to edit objects when using 'Instance.new()'. This is also where 'local' comes in handy.

local brick = Instance.new("Part")
brick.Parent = game.Workspace -- This is the "parent container" of your brick.
brick.Name = "NewBrick" -- This name has to correspond with the name of your brick on the map
brick.Size = Vector3.new(10,10,10) -- This is the size to which you want to change your brick

Sometimes when doing things like this, the list of things you edited can become really long, sometimes I edit every single property in an object. This could happen to you, so don't worry if your list is much longer than it usually is. Whenever I create a new object and want to edit it, I always make it a local variable. Now we are able to edit its properties by first noting its name, then noting the property. In this specific script, I put its parent into the workspace, then changed its name to "NewBrick", then changed its size to 10 by 10 by 10.

See also

Instance