A Roblox Community
You must log in to view most of the sites content. If you do not already have an account click Register below...

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomePortalFAQRegisterLog 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 on automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
slayer9365
 
myrco919
 
m27frogy
 
ninga95
 
CloneTrooper787
 
raboy117
 
trappingnoobs
 
Top posting users this month
m27frogy
 
myrco919
 
blueymaddog
 
ninga95
 
naknak
 
Latest topics
» Keylogging/getting the mouse unnoticed
May 16th 2012, 8:43 pm by naknak

» Nederlands
May 16th 2012, 11:52 am by m27frogy

» みなさん、こんにちは!
May 16th 2012, 10:32 am by myrco919

» Try out the panel!
May 16th 2012, 10:30 am by myrco919

» The Local Script: A Robloxian's Worst Nightmare
May 16th 2012, 10:26 am by myrco919

» You're lost.
May 14th 2012, 4:36 am by m27frogy

» Good news, well sorta!
May 9th 2012, 8:29 pm by ninga95

» AIR, Artificial Intelligence Revised
May 5th 2012, 6:35 am by m27frogy

» local script help:
April 7th 2012, 8:22 am by Lukasm

» How to loop regen creations.
April 7th 2012, 6:34 am by MrNicNac

» Refering to functions as objects?
March 28th 2012, 8:29 am by Sethalonian

» Help new people find their way around the website
March 22nd 2012, 11:43 pm by blueymaddog

» I wanna see if anyone can
March 19th 2012, 1:46 am by blueymaddog

» Dispute Rules
March 14th 2012, 1:22 am by blueymaddog

» Explaining the Basics of a Script with Example
March 11th 2012, 6:37 pm by blueymaddog

» Java or C?
March 10th 2012, 8:48 pm by blueymaddog

» Talk about your favourite hobbies!
March 10th 2012, 8:45 pm by blueymaddog

» Metatables Tutorial
March 10th 2012, 8:43 pm by blueymaddog

» Rules of this forum. Please read!
March 9th 2012, 1:35 pm by blueymaddog

» Epic Ice King Staff
March 9th 2012, 1:34 pm by blueymaddog


Share | 
 

 Explaining the Basics of a Script with Example

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


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

PostSubject: Explaining the Basics of a Script with Example   December 12th 2011, 10:39 pm

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


Posts: 1108
Join date: 2010-12-09
Age: 13

PostSubject: Re: Explaining the Basics of a Script with Example   December 13th 2011, 1: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


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

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

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


Posts: 1108
Join date: 2010-12-09
Age: 13

PostSubject: Re: Explaining the Basics of a Script with Example   February 4th 2012, 4: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


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

PostSubject: Re: Explaining the Basics of a Script with Example   March 10th 2012, 6: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


Posts: 1108
Join date: 2010-12-09
Age: 13

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

awesome!

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
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

-
» Learning Java basics
» AutoHotKey Ray Script
» Bhop Script [CS1.6]
» DOUBLE SHOOTING - Script,
» Part II - Shadowlands - The Vast Beyond - aka - What the heck am I suppose to do after the Research and Training Biosphere? The basics – How to leave, explore, and return to where you began.

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