<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Explaining_Scripts</id>
	<title>Explaining Scripts - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Explaining_Scripts"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Explaining_Scripts&amp;action=history"/>
	<updated>2026-07-28T17:08:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.starfall.wtf/index.php?title=Explaining_Scripts&amp;diff=482&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;{{CatUp|Tutorials}} __TOC__  == Introduction ==  This article will explain each line of some big scripts and basic commands, from basic to advanced scripting. Before you read this tutorial, I recommend you see this first: #Absolute beginner&#039;s guide to scripting #Basic Scripting Note: This is only useful in Roblox Studio.  == Basic Commands ==  First of all, let me tell you about the very basic commands. Put this script into a part and we&#039;ll...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Explaining_Scripts&amp;diff=482&amp;oldid=prev"/>
		<updated>2024-12-10T22:14:14Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{CatUp|Tutorials}} __TOC__  == Introduction ==  This article will explain each line of some big scripts and basic commands, from basic to advanced scripting. Before you read this tutorial, I recommend you see this first: #&lt;a href=&quot;/index.php/Absolute_beginner%27s_guide_to_scripting&quot; title=&quot;Absolute beginner&amp;#039;s guide to scripting&quot;&gt;Absolute beginner&amp;#039;s guide to scripting&lt;/a&gt; #&lt;a href=&quot;/index.php/Basic_Scripting&quot; title=&quot;Basic Scripting&quot;&gt;Basic Scripting&lt;/a&gt; Note: This is only useful in &lt;a href=&quot;/index.php/Roblox_Studio&quot; class=&quot;mw-redirect&quot; title=&quot;Roblox Studio&quot;&gt;Roblox Studio&lt;/a&gt;.  == Basic Commands ==  First of all, let me tell you about the very basic commands. Put this script into a &lt;a href=&quot;/index.php/Part&quot; class=&quot;mw-redirect&quot; title=&quot;Part&quot;&gt;part&lt;/a&gt; and we&amp;#039;ll...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{CatUp|Tutorials}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This article will explain each line of some big scripts and basic commands, from basic to advanced scripting. Before you read this tutorial, I recommend you see this first:&lt;br /&gt;
#[[Absolute beginner&amp;#039;s guide to scripting]]&lt;br /&gt;
#[[Basic Scripting]]&lt;br /&gt;
Note: This is only useful in [[Roblox_Studio|Roblox Studio]].&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&lt;br /&gt;
First of all, let me tell you about the very basic commands. Put this script into a [[part]] and we&amp;#039;ll take it from there.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
print(&amp;quot;Hi Mom!&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets analyze it:&lt;br /&gt;
&lt;br /&gt;
The first line:&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Thist declares a function, a utility to the script. This utility is &amp;quot;onTouched&amp;quot;, meaning &amp;quot;when touched&amp;quot;. Then it says &amp;quot;(hit)&amp;quot;. &amp;quot;Hit&amp;quot; is another [[Variables|variable]] that represents the thing that touched it. So when you touch the brick, the following will occur:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;print(&amp;quot;Hi Mom!&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will print the simple phrase &amp;quot;Hi Mom!&amp;quot; in the [[Output|Output Toolbar]] once the part has been touched.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;end&amp;lt;/pre&amp;gt;&lt;br /&gt;
This ends the onTouched function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
First, &amp;quot;script.Parent&amp;quot; means the location in the Roblox Studio of the script, which will be the brick into which this script is inserted.  Then we have Touched:connect(onTouched) that connects the touched function with the brick touched.&lt;br /&gt;
&lt;br /&gt;
== If Commands ==&lt;br /&gt;
&lt;br /&gt;
Creates a condition to the script. Something will only be possible if the condition is real. Lets see:&lt;br /&gt;
&amp;lt;pre&amp;gt;i = 1&lt;br /&gt;
if (i == 1) then&lt;br /&gt;
print (&amp;quot;Hello! Thats correct!&amp;quot;)&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
First we declare a value (i) and we say its value is 1.&lt;br /&gt;
If i value = 1, then we print &amp;quot;Hello...&amp;quot; message!&lt;br /&gt;
Of course, we have another commands to be used in if.&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;pre&amp;gt;if (i.Parent == game.Workspace) then&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will only work if i&amp;#039;s parent is game.Workspace.&lt;br /&gt;
&amp;lt;pre&amp;gt;if (i.Parent == nil)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nil means non-existent, so this will only run if i doesn&amp;#039;t exist or it is inside another parent.&lt;br /&gt;
#== - equals, the function will happen if true (i==1)&lt;br /&gt;
#~= - different, the function will happen if false (i~=2)&lt;br /&gt;
#&amp;lt; - smaller, applicable only to values(i&amp;lt;5)&lt;br /&gt;
#&amp;lt;= - smaller or equal, will happen if i equals 5 or less(i&amp;lt;=5)&lt;br /&gt;
#&amp;gt; - bigger.&lt;br /&gt;
#&amp;gt;= - bigger or equal.&lt;br /&gt;
Also we can use equality of variables or non-existence.&lt;br /&gt;
&amp;lt;pre&amp;gt;if (i.Parent == game.Workspace) then&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will only work if i&amp;#039;s parent is game.Workspace.&lt;br /&gt;
&amp;lt;pre&amp;gt;if (i.Parent == nil)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Nil means non-existent, so this will only run if it doesn&amp;#039;t exist or it is inside another parent.&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
&lt;br /&gt;
A loop is something that goes on and on until something declare is false or wrong.&lt;br /&gt;
We have three types of loops.&lt;br /&gt;
#For i = 1&lt;br /&gt;
#While true do&lt;br /&gt;
#Repeat&lt;br /&gt;
&lt;br /&gt;
&amp;quot;For i = 1&amp;quot; is used as a condition: if i is 1 than it will repeat until i is not 1. We can also use a marked number of loops.&lt;br /&gt;
&amp;lt;pre&amp;gt;A = 3&lt;br /&gt;
for i = 1, A do&lt;br /&gt;
print(&amp;quot;Hello,World!&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This script would do A times the loop, and since A is 3, it would print 3 times &amp;quot;Hello,World!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
A while true do loop will repeat and repeat and repeat until forever.&lt;br /&gt;
&amp;lt;pre&amp;gt;while true do&lt;br /&gt;
wait(2)&lt;br /&gt;
print(&amp;quot;WOOOOOT&amp;quot;)&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
The wait line makes it wait 2 seconds before printing. It will repeat the &amp;quot;WOOOOOT&amp;quot; message each 2 seconds. You can change it if you like.&lt;br /&gt;
&lt;br /&gt;
A Repeat loop does the same as a for loop, only its simplier and it will repeat until a condition.&lt;br /&gt;
&amp;lt;pre&amp;gt;i = 0&lt;br /&gt;
repeat&lt;br /&gt;
i = i + 1&lt;br /&gt;
print(i)&lt;br /&gt;
until (i == 5)&lt;br /&gt;
print(&amp;quot;No more loop!&amp;quot;)&lt;br /&gt;
wait(3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is print &amp;quot;No more loop&amp;quot; only when i value is at 5. Dont mind at Instance. We will come to it later. Each 3 seconds the script checks if i value is 5. If it is, we have a print. If not, it loops until i is 5.&lt;br /&gt;
&lt;br /&gt;
== Instance ==&lt;br /&gt;
&lt;br /&gt;
Is a command used to create things. You can create a brick from scratch to a explosion! See:&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
local brick = Instance.new(&amp;quot;Part&amp;quot;)&lt;br /&gt;
brick.Parent = game.Workspace&lt;br /&gt;
brick.Name = &amp;quot;Brick&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you insert this code in a new script and run it, when something touches it will create infinite bricks while you are standing on it because we don&amp;#039;t have a if system and it could lag your computer and even bug your program!&lt;br /&gt;
&lt;br /&gt;
Continue...&lt;br /&gt;
&amp;quot;local brick = Instance.new(&amp;quot;Part&amp;quot;)&amp;quot; line makes a local variable (only works in the creation script) called brick and defines it as a new Part.&lt;br /&gt;
We call its parent in game.Workspace, the normal address, and we define its name as &amp;quot;Brick&amp;quot;!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;local e = Instance.new(&amp;quot;Explosion&amp;quot;)&lt;br /&gt;
e.Parent = game.Workspace&amp;lt;/pre&amp;gt;&lt;br /&gt;
This script creates a explosion called as e variable and defines its adress in game.Workspace. (BOOM!) To define its values its another history.&lt;br /&gt;
&lt;br /&gt;
== Locals and Globals ==&lt;br /&gt;
:&amp;#039;&amp;#039;&amp;#039;See also: [http://lua-users.org/wiki/ScopeTutorial]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
A local variable is declared using the &amp;lt;code&amp;gt;local&amp;lt;/code&amp;gt; keyword. A local variable is only valid within it&amp;#039;s scope , or enclosing block. For scope purposes, a script is considered an enclosing block. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local foobar = &amp;quot;Goodbye World&amp;quot;&lt;br /&gt;
&lt;br /&gt;
function foo()&lt;br /&gt;
	local bar = &amp;quot;Hello World&amp;quot;&lt;br /&gt;
	baz = &amp;quot;Global variable&amp;quot; --Note the absence of a local modifier&lt;br /&gt;
	print(bar)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
foo() --Prints &amp;quot;Hello World&amp;quot;&lt;br /&gt;
print(bar) --Bar is out of scope, so prints nil&lt;br /&gt;
print(baz) --Baz is global, and therefore always in scope, so prints &amp;quot;Global variable&amp;quot;&lt;br /&gt;
print(foobar) --FooBar is in scope, so prints &amp;quot;Goodbye World&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Global variables, once declared, can be accessed anywhere (although current restrictions limit them to the scope of the script).&lt;br /&gt;
&lt;br /&gt;
== Vector3 ==&lt;br /&gt;
&lt;br /&gt;
Vector3 is a code made by three values (x,y,z) used in sizes definitions to positions. Y is height and x and z is sideways.&lt;br /&gt;
&amp;lt;pre&amp;gt;e = Instance.new(&amp;quot;Part&amp;quot;)&lt;br /&gt;
e.Parent = game.Workspace&lt;br /&gt;
e.Name = &amp;quot;Brick&amp;quot;&lt;br /&gt;
e.Size = Vector3.new(2,1,2)&lt;br /&gt;
e.Position = Vector3.new(10,10,10)&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is create a brick called &amp;quot;Brick&amp;quot; with a size of 2x2 and tall 1, or in the correct way a 2x1x2 brick. And its position is 10,10,10 used as coordinates in the game.&lt;br /&gt;
&lt;br /&gt;
== Humanoids == &lt;br /&gt;
&lt;br /&gt;
It means the human part of a brick. Like a player or a monster. If both have healths, can get damage and can walk, jump, and others, they are humanoids.&lt;br /&gt;
We can use many functions and commands to humanoids, like loose life, increase max health, walk, and conditions too!&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function onTouched(hit)&lt;br /&gt;
local human = hit.Parent:findFirstChild(&amp;quot;Humanoid&amp;quot;) &lt;br /&gt;
if (human == nil) then return end &lt;br /&gt;
print(&amp;quot;*Hit by a human*&amp;quot;)&lt;br /&gt;
end &lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
FindFirstChild is only a search for the Parent that the script does and it uses the first thing named found!&lt;br /&gt;
&amp;lt;pre&amp;gt;local human = hit.Parent:findFirstChild(&amp;quot;Humanoid&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
This makes a local called human and it says that human is the first thing found called Humanoid (meaning, a human)in the hit&amp;#039;s parent.&lt;br /&gt;
In the fourth line we make a condition:&lt;br /&gt;
&amp;lt;pre&amp;gt;if (human == nil) then return end&amp;lt;/pre&amp;gt;&lt;br /&gt;
If human is unexistant then returns and it ends. Meaning: if a humanoid didn&amp;#039;t touch that, it won&amp;#039;t do anything.&lt;br /&gt;
Otherwise, if a human touched that(human~=nil)...&lt;br /&gt;
&amp;lt;pre&amp;gt;print(&amp;quot;*Hit by a human*&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Prints &amp;quot;*Hit by a human*&amp;quot;. This condition is very useful for buttons and other things you don&amp;#039;t want to be active with only a rocket or a bullet. &lt;br /&gt;
&lt;br /&gt;
Now, health.[[How to make lava]] is a good example of a health condition.&lt;br /&gt;
If a human touches it. Its life is 0.&lt;br /&gt;
We can also increase the life of a human.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function onTouched(hit)&lt;br /&gt;
local human = hit.Parent:findFirstChild(&amp;quot;Humanoid&amp;quot;) &lt;br /&gt;
if (human == nil) then return end &lt;br /&gt;
human.MaxHealth = 500&lt;br /&gt;
human.Health = human.MaxHealth&lt;br /&gt;
end &lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
This makes the human&amp;#039;s maximum health increase to 500, and then makes the human&amp;#039;s current health equal to that maximum health (which is 500).&lt;br /&gt;
Using MoveTo, we can order a humanoid to walk somewhere.  You will need to create a brick that will trigger the following script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
local human = hit.Parent:findFirstChild(&amp;quot;Humanoid&amp;quot;) &lt;br /&gt;
if (human == nil) then return end &lt;br /&gt;
base = game.Workspace.base&lt;br /&gt;
human:MoveTo(Vector3.new(10,10,10), base)&lt;br /&gt;
end &lt;br /&gt;
script.Parent.Touched:connect(onTouched)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will make the human walk to coordinates 10,10,10.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
#[[Your first script]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>