<?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=Basic_Scripting</id>
	<title>Basic Scripting - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Basic_Scripting"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Basic_Scripting&amp;action=history"/>
	<updated>2026-07-28T16:13:51Z</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=Basic_Scripting&amp;diff=401&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;{{CatUp|Tutorials}} __TOC__  == Introduction ==  This article is an easy way to get started scripting.  This will teach you how to  script simple scripts that trigger when you touch them from the start.  == Requirements ==  This tutorial is for people familiar with ROBLOX, and know Roblox Studio very well (a few weeks of experience). They should be familiar with  [https://cirkl.wiki/index.php?title=Image:Explorerwindow.JPG Explorer], Properties, and...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Basic_Scripting&amp;diff=401&amp;oldid=prev"/>
		<updated>2024-12-10T12:38:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{CatUp|Tutorials}} __TOC__  == Introduction ==  This article is an easy way to get started scripting.  This will teach you how to  script simple scripts that trigger when you touch them from the start.  == Requirements ==  This tutorial is for people familiar with ROBLOX, and know &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; very well (a few weeks of experience). They should be familiar with  [https://cirkl.wiki/index.php?title=Image:Explorerwindow.JPG Explorer], &lt;a href=&quot;/index.php/Properties&quot; title=&quot;Properties&quot;&gt;Properties&lt;/a&gt;, and...&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 is an easy way to get started scripting.  This will teach you how to &lt;br /&gt;
script simple scripts that trigger when you touch them from the start.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This tutorial is for people familiar with ROBLOX, and know [[Roblox_Studio|Roblox Studio]] very well (a few weeks of experience). They should be familiar with  [https://cirkl.wiki/index.php?title=Image:Explorerwindow.JPG Explorer], [[Properties]], and [https://cirkl.wiki/index.php/index.php?title=Image:Outputwindow.JPG Output].&lt;br /&gt;
&lt;br /&gt;
== Important Things To Remember When Scripting ==&lt;br /&gt;
&lt;br /&gt;
Spelling is very important when scripting. If you misspell something, your script will not work properly. Most of the time, &amp;#039;&amp;#039;Output&amp;#039;&amp;#039; will catch these simple syntax (spelling) errors. To open the output window go to view--&amp;gt;Output.&lt;br /&gt;
&lt;br /&gt;
== Before Starting ==&lt;br /&gt;
&lt;br /&gt;
Before you can script, you must have something to put your script in. I suggest finishing your map before starting any scripting. To start out, we will make a simple door that opens by a button. After you make the door and button, group it and name the door &amp;quot;Door&amp;quot; and the button &amp;quot;Button.&amp;quot; Then you have to insert a script into the button. To do that select the button, then in the menu, do Insert -&amp;gt; Object -&amp;gt; &amp;quot;Script&amp;quot;. Now you have to open it. While in Explorer, select the button again, click the plus sign, and double click on the Script. All that should be there is &amp;#039;&amp;#039;print(&amp;quot;Hello World!&amp;quot;)&amp;#039;&amp;#039;, which is the default text that you should remove. Then, you can start actually scripting!&lt;br /&gt;
&lt;br /&gt;
WARNING ! If the door is composed of more than one brick, you must name all the bricks.&lt;br /&gt;
&lt;br /&gt;
== Lines To Remember ==&lt;br /&gt;
&lt;br /&gt;
These are lines that are best to remember, you will use these in most scripts.&lt;br /&gt;
This is the first major line you will use,&lt;br /&gt;
&amp;lt;pre&amp;gt; function onTouched(hit) &amp;lt;/pre&amp;gt;&lt;br /&gt;
which is the &amp;#039;&amp;#039;function&amp;#039;&amp;#039; line for touch scripts.&lt;br /&gt;
&lt;br /&gt;
Note again that the spacing and capitalization are very important.&lt;br /&gt;
The next major line is the last one to most scripts:&lt;br /&gt;
&amp;lt;pre&amp;gt; script.Parent.Touched:connect(onTouched) &amp;lt;/pre&amp;gt;&lt;br /&gt;
This will make the script activate when the script&amp;#039;s &amp;#039;&amp;#039;Parent&amp;#039;&amp;#039; , the button, is touched. Don&amp;#039;t forget these lines, as an error in one of these is common.&lt;br /&gt;
&lt;br /&gt;
== What Scripts Can Do ==&lt;br /&gt;
&lt;br /&gt;
If one looks in the [[Properties|properties]] window while having a brick selected one will see several variables such as: BrickColor, Size, CanCollide, and Transparency. Anything in the [[Properties|properties]] window can be altered in a script. &lt;br /&gt;
&lt;br /&gt;
To make the door invisible, change the Transparency property:&lt;br /&gt;
&amp;lt;pre&amp;gt; script.Parent.Parent.Door.Transparency = 1 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: Remember that script.Parent represents the button.  The parent of the button is the grouped model - which contains the bricks called Door and Button.  So script.Parent.Parent is refering to the model.  The next step is script.Parent.Parent.Door which will give you access to the brick called Door. &lt;br /&gt;
 &lt;br /&gt;
To make a door such that one can walk through it, change the CanCollide property:&lt;br /&gt;
&amp;lt;pre&amp;gt; script.Parent.Parent.Door.CanCollide = false &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How do you know if you use numbers or True/False? If the property has a checkbox, then it is true or false, true being checked, and false being unchecked. If it is a value, like transparency is, then it is a number between 0 and 1. If it has a drop down menu, like BrickColor, then it has a value for each item in the menu. Usually the values are pretty random, starting at 0. BrickColor codes are in this page: [[Scripting]].&lt;br /&gt;
&lt;br /&gt;
So, our script so far is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
	script.Parent.Parent.Door.Transparency = 1&lt;br /&gt;
	script.Parent.Parent.Door.CanCollide = false&lt;br /&gt;
	script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
But, we forgot one thing. Ends! You need an &amp;#039;&amp;#039;end&amp;#039;&amp;#039; to finish the functions and other pieces of code. We need one &amp;#039;&amp;#039;end&amp;#039;&amp;#039; to finish every function. So, if you have 5 functions, you will have 5 ends.&lt;br /&gt;
The ends go right before the ending line, like this.&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
	script.Parent.Parent.Door.Transparency= 1&lt;br /&gt;
	script.Parent.Parent.Door.CanCollide= false&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
But we still need to make the door solid again after a while, so we will add a &amp;#039;&amp;#039;wait&amp;#039;&amp;#039; function by using this line:&lt;br /&gt;
&amp;lt;pre&amp;gt;wait(3)&amp;lt;/pre&amp;gt;&lt;br /&gt;
That waits 3 seconds before going to the next line. Now to return the door to its original state:&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
	script.Parent.Parent.Door.Transparency= 1 -- an invisible door&lt;br /&gt;
	script.Parent.Parent.Door.CanCollide= false -- a walkthroughable door&lt;br /&gt;
	wait(3)&lt;br /&gt;
	script.Parent.Parent.Door.Transparency= 0.3  -- a partially visible door &lt;br /&gt;
	script.Parent.Parent.Door.CanCollide= true -- a door you can&amp;#039;t walk through anymore&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
That is a working door, but there are shortcuts to make it easier. You can see a lot of repetition (&amp;quot;script.Parent.Parent.Door&amp;quot;) so we can make that easier.&lt;br /&gt;
&lt;br /&gt;
WARNING: &lt;br /&gt;
If your door is a group of 2 bricks (or more), called e.g., &amp;quot;Door&amp;quot;, which is a group of the bricks BodyA and BodyB:&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
	script.Parent.Parent.Door.BodyA.Transparency= 1&lt;br /&gt;
	script.Parent.Parent.Door.BodyB.Transparency= 1&lt;br /&gt;
        script.Parent.Parent.Door.BodyA.CanCollide= false&lt;br /&gt;
        script.Parent.Parent.Door.BodyB.CanCollide= false&lt;br /&gt;
        wait(3)&lt;br /&gt;
	script.Parent.Parent.Door.BodyA.Transparency= 0.3&lt;br /&gt;
	script.Parent.Parent.Door.BodyB.Transparency= 0.3&lt;br /&gt;
        script.Parent.Parent.Door.BodyA.CanCollide= true&lt;br /&gt;
        script.Parent.Parent.Door.BodyB.CanCollide= true&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Every brick that composes the door must be scripted.&lt;br /&gt;
&lt;br /&gt;
== Another example ==&lt;br /&gt;
&lt;br /&gt;
Before the &amp;#039;&amp;#039;function onTouched(hit)&amp;#039;&amp;#039; line, define the door with this line:&lt;br /&gt;
&amp;lt;pre&amp;gt;door = script.Parent.Parent.Door&amp;lt;/pre&amp;gt;&lt;br /&gt;
If we have that, we can shorten the script:&lt;br /&gt;
&amp;lt;pre&amp;gt;door = script.Parent.Parent.Door&lt;br /&gt;
function onTouched(hit)&lt;br /&gt;
	door.Transparency = 1&lt;br /&gt;
	door.CanCollide = false&lt;br /&gt;
	wait(3)&lt;br /&gt;
	door.Transparency = 0.3&lt;br /&gt;
	door.CanCollide = true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
WARNING : With a door of 2 bricks called for the example Body A and BodyB&lt;br /&gt;
&amp;lt;pre&amp;gt;door = script.Parent.Parent.Door&lt;br /&gt;
function onTouched(hit)&lt;br /&gt;
	door.BodyA.Transparency= 1&lt;br /&gt;
	door.BodyB.Transparency= 1&lt;br /&gt;
        door.BodyA.CanCollide= false&lt;br /&gt;
        door.BodyB.CanCollide= false&lt;br /&gt;
        wait(3)&lt;br /&gt;
	door.BodyA.Transparency= 0.3&lt;br /&gt;
	door.BodyB.Transparency= 0.3&lt;br /&gt;
        door.BodyA.CanCollide= true&lt;br /&gt;
        door.BodyB.CanCollide= true&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Explosions, Messages, and More! ==&lt;br /&gt;
&lt;br /&gt;
You can even insert things like, Explosions, Messages, Values, and more.  A full list of what you can insert is here: [[Class reference]]. The most common ones, however, are:&lt;br /&gt;
#IntValue&lt;br /&gt;
#Message&lt;br /&gt;
#Explosion&lt;br /&gt;
With the things you insert you have to define parts to it. Try inserting these things while in studio to see what you have to define. With the &amp;#039;&amp;#039;Message&amp;#039;&amp;#039; you have to define:&lt;br /&gt;
#Parent&lt;br /&gt;
#Text&lt;br /&gt;
Explosion:&lt;br /&gt;
#Parent&lt;br /&gt;
#BlastRadius&lt;br /&gt;
#BlastPressure&lt;br /&gt;
#Position&lt;br /&gt;
IntValue:&lt;br /&gt;
#Parent&lt;br /&gt;
#Value&lt;br /&gt;
&lt;br /&gt;
Lets make a message block.  We&amp;#039;ll start with the lines to remember:&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
end&lt;br /&gt;
script.Parent.Touched(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, to insert the message object:&lt;br /&gt;
&amp;lt;pre&amp;gt; msg = Instance.new(&amp;quot;Message&amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, the things we have to define are Parent and Text:&lt;br /&gt;
&amp;lt;pre&amp;gt; msg.Parent = game.Workspace &lt;br /&gt;
msg.Text = &amp;quot;This is the sample message text.&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
But we need to make it go away, after 3 seconds. The remove() function will remove the message from the screen. Remember to put a colon between msg and remove:&lt;br /&gt;
&amp;lt;pre&amp;gt;wait(3)&lt;br /&gt;
msg:remove()&amp;lt;/pre&amp;gt;&lt;br /&gt;
So, now the whole thing:&lt;br /&gt;
&amp;lt;pre&amp;gt;function onTouched(hit)&lt;br /&gt;
	msg = Instance.new(&amp;quot;Message&amp;quot;)&lt;br /&gt;
	msg.Parent = game.Workspace&lt;br /&gt;
	msg.Text = &amp;quot;This is the sample message text.&amp;quot;&lt;br /&gt;
	wait(3)&lt;br /&gt;
	msg:remove()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you try to touch this, you will see a bunch of messages because the onTouched function will keep going over and over. To fix this, use [[Debounce]].&lt;br /&gt;
&lt;br /&gt;
If you use debounce, it will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;debounce = false&lt;br /&gt;
function onTouched(hit)&lt;br /&gt;
	if debounce == false then&lt;br /&gt;
		debounce = true&lt;br /&gt;
		msg = Instance.new(&amp;quot;Message&amp;quot;)&lt;br /&gt;
		msg.Parent = game.Workspace&lt;br /&gt;
		msg.Text = &amp;quot;This is the sample message text.&amp;quot;&lt;br /&gt;
		wait(3)&lt;br /&gt;
		msg:remove()&lt;br /&gt;
		debounce = false&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
script.Parent.Touched:connect(onTouched)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
Loops are what you use to make things repeat; Instead of copying and paste dozens of times. There are 3 different types of loops.&lt;br /&gt;
#While true do&lt;br /&gt;
#For loop&lt;br /&gt;
#Repeat loop&lt;br /&gt;
&lt;br /&gt;
===While true do===&lt;br /&gt;
&lt;br /&gt;
While loops need ends to show where they go back to the beginning. We only need one end here too because there is no function. Here&amp;#039;s the whole script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;while true do&lt;br /&gt;
wait(001) -- change this time to however many seconds you DON&amp;#039;T want there to be a message&lt;br /&gt;
msg = Instance.new(&amp;quot;Message&amp;quot;)&lt;br /&gt;
msg.Parent = game.Workspace&lt;br /&gt;
msg.Text = &amp;quot;Please send me a friend request!&amp;quot;&lt;br /&gt;
wait(300) -- change this time to however many seconds you want the message to remain&lt;br /&gt;
msg:remove()&lt;br /&gt;
end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===For loop===&lt;br /&gt;
&amp;quot;for&amp;quot; is used to make something go a set number of times. Unlike while true do the makes it go constantly.&lt;br /&gt;
For Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
T = 5 --How many times it does it.&lt;br /&gt;
&lt;br /&gt;
for i = 1, T do&lt;br /&gt;
b = Instance.new(&amp;quot;Part&amp;quot;)&lt;br /&gt;
b.Parent = game.Workspace &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This would insert a part into the work space 5 times.&lt;br /&gt;
====Getting Children====&lt;br /&gt;
It is possible to use &amp;quot;for&amp;quot; to get to children of anything, e.g.,:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a = game.Workspace:GetChildren()&lt;br /&gt;
for i = 1, #a do&lt;br /&gt;
if (a[i].className == &amp;quot;part&amp;quot;) then&lt;br /&gt;
a[i].Reflectance = 1&lt;br /&gt;
else return end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Repeat loops===&lt;br /&gt;
This way to make something loop is rarely used. You can use a for loop do do anything that repeat can do but repeat is simpler.&lt;br /&gt;
For Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
repeat&lt;br /&gt;
Nv = Instance.new(&amp;quot;NumberValue&amp;quot;)&lt;br /&gt;
Nv.value = Nv.value + 1&lt;br /&gt;
until (Nv.value == 8) then&lt;br /&gt;
print(&amp;quot;It stops at 8&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>