Instance: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>GoldenUrg
disamguitation note - recommend rename
>JulienDethurens
Redirected page to RBX.lua.Instance (Object)
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{CatUp|Tutorials}}
#redirect [[RBX.lua.Instance (Object)]]
__TOC__
 
{{LeftNoticeStart}}
'''Disambiguation''': This page refers to the Instance table used to create new objects.
 
See [[RBX.lua.Instance (Object)|RBX.lua.Instance]] for the Instance class of objects.
|}
 
== Introduction ==
An "Instance" refers to an [[RBX.lua.Instance (Object)|Instance]] of an Object, hence the name.  The Instance table is a very useful for creating Objects within a script.  It can be used to create just about anything, and it is used often in [[User:Anaminus|Anaminus]]' Script Builder, and adding Messages via scripts in many places.
 
It is different from:
 
<pre>
local o = game.Workspace.Object:Clone()
o.Parent = game.Workspace
</pre>
 
Instance actually creates an Object from scratch, instead of copying from somewhere else.
In the next section, we will take a look at some examples.
 
== Creating a Message ==
 
<pre>
local msg = Instance.new("Message")
 
msg.Parent = game.Workspace
msg.Text = "Hello."
wait(10)
msg:Remove()
</pre>
 
In the above script, you see that "Instance.new" is creating a new object, a message, and making it's variable name "msg".  The rest of the script then tells "msg" what to do.
 
== Creating a Part ==
 
<pre>
local p = Instance.new("Part")
 
p.Parent = game.Workspace
p.Name = "Brick"
p.BrickColor = BrickColor.new(21)
 
p.Anchored = true
</pre>
 
In the above script, "Instance.new" is creating a Part Object, with a variable name of "p", and again, the script tells it what it wants to do.  This script is very useful indeed.
 
== Creating an Explosion ==
 
<pre>
local e = Instance.new("Explosion")
 
e.Parent = game.Workspace
</pre>
In the above script, "Instance.new" is creating a Explosion Object, with a variable name of "e".
 
==Creating Sparkles==
 
<pre>
local g = Instance.new("Sparkles") --This creates the Sparkles
 
g.Parent = game.Workspace.Player.Torso --Change Player to your Character's name and Torso to a part you want the sparkles to be in, so its basicly saying that the Sparkles will go in Player's torso.
</pre>
 
[[Category:Scripting Tutorials]]

Latest revision as of 03:46, 25 March 2012