A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Explaining the Basics of a Script with Example

View previous topic View next topic Go down 
AuthorMessage
IsAPotato
Novice Scripter
Novice Scripter
avatar

Posts : 16
Join date : 2011-06-04
Location : California

PostSubject: Explaining the Basics of a Script with Example   December 13th 2011, 2:39 am

Ok, so today we will go over a very simple script piece by piece. It's probably one of the most used scripts on Roblox, but I think it's great instructional material for beginners. So, here we go. Post complaints, criticisms, and other stuff if you like.

-------------------------------------------------

Right, today we will be disecting a basic killing script. Many people use this to simulate lava in games so we will assume we are going to do the same. Now for your lava brick. To start off we need to define your function. A function name can be anything because it is a variable. So for now we will just name it "LavaBrick".

Code:
function LavaBrick(Hit)

Now you also put parenthesis's after functions, because they take function arguments or parameters. Now we need to tell your script what to look for so it can kill it. The function argument here is "Hit". This will later be defined as what hit the brick. So..

Code:
function LavaBrick(Hit)
LavaTarget = Hit.Parent:findFirstChild("Humanoid")

Right, so LavaTarget is a variable representing what hit the brick. In it is your function argument "Hit". So, if a Robloxian hit the brick, it would touch their legs. "Hit.Parent" Is in this case the parent of the legs which would be everything in the player model. So now we have the method ":findFirstChild()". Methods like this start with a ":" and also have parenthesis for arguments. So in the parenthesis we have "Humanoid". This would go to what hit the brick, find its parent, then search through the model for the first thing named Humanoid. Now the script knows what it is and has it tagged and saved as a variable.

Code:
function LavaBrick(Hit)
LavaTarget = Hit.Parent:findFirstChild("Humanoid")
if (LavaTarget ~= nil) then

So basically it's just checking to see if the Humanoid is not nil. By the way, nil means nothing or zero.

Code:
function LavaBrick(Hit)
LavaTarget = Hit.Parent:findFirstChild("Humanoid")
if (LavaTarget ~= nil) then
LavaTarget.Health = 0

Now inside the Humanoid their is a property called Health. This represents how much health your character currently has. So here, we are going inside the Humanoid and setting its health to zero.

Code:
function LavaBrick(Hit)
LavaTarget = Hit.Parent:findFirstChild("Humanoid")
if (LavaTarget ~= nil) then
LavaTarget.Health = 0
end
end
script.Parent.Touched:connect(LavaBrick)

Now, we have two ends here for a reason. The only things that need ends are functions, if's, and do's. We have one "function" and one "if" so we need two ends. Get it? Now the very last bit is the connection line. It's finding your script, then its parent which would be the brick. Now it uses the "Touched" event. When you see functions with the variable "Touch" or "Touched" it does not mean that is an event. The Touched event is for any type of brick being touched. So it finds the scripts parent, which is the brick, and connects the Touched function. Then there is ":connect(LavaBrick)". This does exactly what it says, it connects the function to the connection line so the script can run. Without a connection line, scripts won't run. I hope you learn from this and the last section of coding is the actual working script. You have to put it in a brick, then copy the brick and step on it. Learn more about scripting for special effects.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Explaining the Basics of a Script with Example   December 13th 2011, 5:43 am

nice tut bro! :)

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
IsAPotato
Novice Scripter
Novice Scripter
avatar

Posts : 16
Join date : 2011-06-04
Location : California

PostSubject: Re: Explaining the Basics of a Script with Example   December 13th 2011, 11:32 am

Thanks. :)
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Explaining the Basics of a Script with Example   February 4th 2012, 8:02 am

'So, here we go. Post complaints, criticisms, and other stuff if you like. '

k I will then XD

tl:dr

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
IsAPotato
Novice Scripter
Novice Scripter
avatar

Posts : 16
Join date : 2011-06-04
Location : California

PostSubject: Re: Explaining the Basics of a Script with Example   March 10th 2012, 10:28 pm

Well, I'm now a wiki writer so I'm replacing the old lava tutorial with this.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Explaining the Basics of a Script with Example   March 11th 2012, 9:37 pm

awesome!

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: Explaining the Basics of a Script with Example   

Back to top Go down
 
Explaining the Basics of a Script with Example
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Gaming basics and our responsibility
» Chess Script
» Autohotkey script for melee barbarian
» Awesome (FREE) gun script!
» Gun Movement Script? Tutorial #2

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Beginner-
Jump to: