How do I create a brick?

From Legacy Roblox Wiki
Jump to navigationJump to search

You've seen huge places where there are many thousands of bricks, and you've seen a good amount of free models that also use bricks in them. So, you might be wondering, "How can I create bricks like those?" If you are in fact wondering that question, this article has the answers!

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. Type this in the command bar, then press enter to allow the code to execute.

Instance.new("Part", game.Workspace)

So here in this command, we see the term 'Instance.new()'. So now, we state the objects className, which is in this case, "Part". Because whenever you create a new object, its parent is nil (nothing), we have to set it somewhere. You could put the parent of the newly created object right inside the parenthesis, separated by a comma. If you don't choose where to place the part, you can do it later.

If you look in the Explorer in the menu, and open up the contents of Workspace, you should see a newly made Script that you made with the previous command.

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", game.Workspace) -- Creating the brick, and placing it into the Workspace
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 10x10x10.

See also

Instance