A Roblox Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeLatest imagesRegisterLog 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
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
naknak
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
Supernapalm
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
m27frogy
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
slayer9365
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
myrco919
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
branefreez
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
ninga95
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
CloneTrooper787
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
raboy117
Explaining the Basics of a Script with Example Vote_lcapExplaining the Basics of a Script with Example Voting_barExplaining the Basics of a Script with Example Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
Explaining the Basics of a Script with Example EmptySeptember 14th 2020, 1:20 pm by MrNicNac

» Send me an Email
Explaining the Basics of a Script with Example EmptySeptember 14th 2020, 1:16 pm by MrNicNac

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
Explaining the Basics of a Script with Example EmptyJuly 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
Explaining the Basics of a Script with Example EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
Explaining the Basics of a Script with Example EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
Explaining the Basics of a Script with Example EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
Explaining the Basics of a Script with Example EmptyApril 13th 2015, 4:54 pm by naknak

» Who's active?!
Explaining the Basics of a Script with Example EmptyApril 13th 2015, 4:52 pm by naknak

» Genesis Point
Explaining the Basics of a Script with Example EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
Explaining the Basics of a Script with Example EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
Explaining the Basics of a Script with Example EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
Explaining the Basics of a Script with Example EmptyJuly 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
Explaining the Basics of a Script with Example EmptyJuly 10th 2014, 11:36 am by naknak

» Hi. I am new here
Explaining the Basics of a Script with Example EmptyApril 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
Explaining the Basics of a Script with Example EmptyJanuary 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
Explaining the Basics of a Script with Example EmptyJanuary 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
Explaining the Basics of a Script with Example EmptyJanuary 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
Explaining the Basics of a Script with Example EmptyNovember 26th 2013, 3:33 pm by Keanu73

» Improve Coding
Explaining the Basics of a Script with Example EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
Explaining the Basics of a Script with Example EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 Explaining the Basics of a Script with Example

Go down 
2 posters
AuthorMessage
IsAPotato
Novice Scripter
Novice Scripter
IsAPotato


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

Explaining the Basics of a Script with Example Empty
PostSubject: Explaining the Basics of a Script with Example   Explaining the Basics of a Script with Example EmptyDecember 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
blueymaddog


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

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

nice tut bro! :)
Back to top Go down
IsAPotato
Novice Scripter
Novice Scripter
IsAPotato


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

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

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


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

Explaining the Basics of a Script with Example Empty
PostSubject: Re: Explaining the Basics of a Script with Example   Explaining the Basics of a Script with Example EmptyFebruary 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
Back to top Go down
IsAPotato
Novice Scripter
Novice Scripter
IsAPotato


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

Explaining the Basics of a Script with Example Empty
PostSubject: Re: Explaining the Basics of a Script with Example   Explaining the Basics of a Script with Example EmptyMarch 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
blueymaddog


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

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

awesome!
Back to top Go down
Sponsored content





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

Back to top Go down
 
Explaining the Basics of a Script with Example
Back to top 
Page 1 of 1
 Similar topics
-
» Some coroutine basics...
» The Local Script: A Robloxian's Worst Nightmare
» how do you script i am a beginner
» Another C++ Script
» Script Help

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