Top posting users this month | |
Latest topics | » Where to go from here.September 14th 2020, 1:20 pm by MrNicNac» Send me an EmailSeptember 14th 2020, 1:16 pm by MrNicNac» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]July 6th 2015, 7:38 pm by m27frogy» New Site PossiblyJuly 6th 2015, 4:16 pm by m27frogy» Ambassador!April 15th 2015, 11:40 pm by naknak» Boop - TagApril 13th 2015, 9:46 pm by naknak» Vip Class ScriptApril 13th 2015, 4:54 pm by naknak» Who's active?!April 13th 2015, 4:52 pm by naknak» Genesis PointJuly 17th 2014, 7:04 pm by branefreez» Reward SystemJuly 17th 2014, 5:41 am by m27frogy» Script RequestJuly 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 hereApril 26th 2014, 4:01 pm by altshiftkey» What's your favorite sport?January 1st 2014, 2:13 pm by m27frogy» FlashLight ScriptJanuary 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 CodingOctober 26th 2013, 1:12 pm by pook03» Simple ButtonSeptember 1st 2013, 6:19 pm by branefreez |
|
| Explaining the Basics of a Script with Example | |
| | Author | Message |
---|
IsAPotato Novice Scripter
Posts : 16 Join date : 2011-06-04 Location : California
| Subject: 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. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Explaining the Basics of a Script with Example December 13th 2011, 5:43 am | |
| | |
| | | IsAPotato Novice Scripter
Posts : 16 Join date : 2011-06-04 Location : California
| Subject: Re: Explaining the Basics of a Script with Example December 13th 2011, 11:32 am | |
| | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: 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 | |
| | | IsAPotato Novice Scripter
Posts : 16 Join date : 2011-06-04 Location : California
| Subject: 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. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Explaining the Basics of a Script with Example March 11th 2012, 9:37 pm | |
| | |
| | | Sponsored content
| Subject: Re: Explaining the Basics of a Script with Example | |
| |
| | | | Explaining the Basics of a Script with Example | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Who is online? | In total there are 3 users online :: 0 Registered, 0 Hidden and 3 Guests
None
Most users ever online was 136 on October 21st 2024, 12:16 pm
|
| Please tell us what time zone you are in here
Got a really good idea? Post it in projects and it might show up here! |
|