How do I create a brick?: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
Maybe we should merge this with instance.
>Mindraker
mNo edit summary
Line 1: Line 1:
{{CatUp|Tutorials}}
__TOC__
==Object Creation via Script==
==Object Creation via Script==


Line 19: Line 22:
</pre>
</pre>


[[Category:Tutorials]]
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 [http://www.lua.org/pil/4.2.html 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.
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 [http://www.lua.org/pil/4.2.html 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.


Line 24: Line 28:


[[Instance]]
[[Instance]]
[[Category:Scripting Tutorials]]

Revision as of 02:12, 4 November 2008

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