Roblox Scripting Made Easy for Beginners! Learn How to Create Games! | Mr. CoolTeacher | Skillshare

Roblox Scripting Made Easy for Beginners! Learn How to Create Games!

Mr. CoolTeacher, Roblox Game Developer, YouTuber

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
13 Lessons (52m)
    • 1. Welcome to the Scripting Club!

      0:57
    • 2. Setting Up Roblox Studio for Scripting

      2:12
    • 3. Explorer Folders Explained

      3:03
    • 4. Use Variables to Stay Clean

      6:21
    • 5. Creating, Cloning, Destroying

      2:57
    • 6. Customzing a Part from a Script

      4:48
    • 7. Use Events to Make Explosive Lava

      4:47
    • 8. Deep Dive Into Functions

      4:26
    • 9. All About If Statements

      6:21
    • 10. Having Fun with While Loops

      2:58
    • 11. It's For Loop Time

      4:56
    • 12. How to Read the Roblox Dev Wiki

      6:52
    • 13. Make Your Own Game!

      1:51
37 students are watching this class

About This Class

Created for You

This guide is designed for everyone, including you! The videos are short, packed with knowledge and have MEMES in them so it'll be a blast to watch for anybody! A course like this is truly nothing you've ever seen before and I really recommend you give it a try if you want to create your own Roblox games!

You've probably always wanted to make your own game. If that's true then this course will really help you because scripting is needed for every game. I really want you to turn your game development dreams into a reality because that's my dream too!

Enjoy Learning

I've been scripting and making games for many years. I've learned how to script fluently through those years so I can teach people effectively. This course took a very long time to create because I wanted to make the learning experience fun! The course is finally available and I hope you're excited to learn!

Learning Goals

In this course you'll learn how to:

  • Open and set up Roblox Studio for scripting
  • Understand what the folders in the explorer are used for
  • Use variables to organize your script
  • Create, clone and destroy from a script
  • Customize a part and turn it into a masterpiece
  • Use events to create explosive lava
  • Use if statements to check things
  • Create your own custom functions
  • While loops and how to break a loop
  • Both types of for loops
  • How to read the wiki

At the end of the course, you're going to get a cool project! The project combines everything you learn from this course to create your very own game!

Transcripts

1. Welcome to the Scripting Club!: you. What's up, guys? I'm Mr Cool Teacher. I've been on roadblocks since 2011. That's a long time. So you can call me Mr Old Teacher. But throughout all of those years, I've learned how to make my own games. And now it's your through. You can your scripting to create your dream game or you conform in some role books where you can make some of those goofy game I in the scripting course. We're learning the basics of roadblocks Lua so that you can start making your own games on roadblocks. We're going to learn how to set up a roadblock studio like a pro with scripter What all these folders mean variables creating cloning and destroying from a script customizing from a script. Then we get more advance, and we learn about events, functions if statements and loops to finish it off. I showed you how to read the wiki, which is really important that no one teaches. If you're really serious about making games and turning your dreams into a reality, you've come to the right place 2. Setting Up Roblox Studio for Scripting: What's up Today we're preparing Roadblock Studio for scripting before Gordon Ramsay cooks. He always needs to prepare his knives and cutting board, and we need to do that, too. No, no, with knives and cutting words. But with menus to start, we need to open up roadblocks. Studio. This is the first step. Don't mess it up, Okay, you can do this from the Roadblocks website by going to any of your games and clicking. Edit If Roadblocks studio didn't open, then you'll get a pop up where you can download it. There's three really important menus that we're going to need for script in the Explorer menu. The Properties menu in the output. Let's open all of these menus first, so it's open the menus. Look at all of the buttons on the top. Where and find one. That's his view. So let's click on the Explorer, the properties and now put to open up the menus. If you don't like the positioning, that's fine. You can move it around just perfect. All right, let's talk about the Explorer. Explorer is like a box for everything in your game. If you make a house, a script, a pet it will show in the Explorer. Now there's a lot of folders in here, and I'll talk about that in the future. But for now, just imagine that it's a box and it holds everything. There's also the properties menu. This one is really cool because it's like a customization menu. So right click on the workspace and go to insert object to insert apart. When we select the part, you can see that the Properties menu gets filled with all of these cool options. Customizing is my favorite part, so let's change the color to wait and let's make it a ball. Let's insert some fire. On the whole, we made a meteor pretty much the properties menu issues to change the way things look or behave, and it's pretty much a customization menu. That's it. Now the output menu. This makes scripting so much easier. This is because the output shows you all of the game breaking errors in your script and the location of it in the script, so it's really useful. There's also warnings, which are orange, and you can also write your own things in there. Those are all the menus needed for now. I hope you're excited the script because we're going to start very soon, 3. Explorer Folders Explained: you guys, It's Mr Cool Teacher here. I hope you have all of the menus open. If you don't, how did you even get here? I showed which menus air needed in the previous video. So should watch that first. So let's take a look at the Explorer menu. We have all these different folders. The first question that you may be asking is why each of these folders air actually different. That's why let's go through all of the important ones. The 1st 1 is a workspace. This one is used to store all the three D objects in your game that could be parts, models, attachments, even particles and explosions. Pretty much things that you could see in touch. The next important folder is the replicated storage. It has storage in the name. So what's it gonna be? You guessed it Storage things in the replicated storage can be anything, and everything in there won't work. So if you have a part or something like that, it will be invisible. If you have a script, it won't do anything. If you have maps in a game, this would be the place to store it because they're all invisible then you can use a script and put it inside of the workspace where things become visible. There's also the server storage. Okay, what is this Replicated storage server storage? Why're there through storage? Folders? Difference. And I'll tell you how. So this is gonna be weird to you, but it's how it works. Pretty much. There's two computers, one computer Is it roll blacks on the other. One is a player's computer. The one of the roadblocks headquarters is called the Server, and the Players computer is called the clients. Everything in the server folders gets stored on Rolexes computers so the players computer can't see it. And also things that happen on the players. Computer don't show for other players. Computers. This is done to prevent Hacker Man anchorman. He's the most powerful actor of all time. If any of that was confusing, it's fine. It's completely fine. It's not too important right now, so we're just forget about it. So you have the server storage and there's actually another server folder. But for scripts called Server script service scripts in this folder started working when the game is created, so it's pretty useful for making things like leaderboards and scripts that you don't want the player to see the starter. Grief older is like the workspace, but instead of three D objects, it holds two D objects. You know how games have buttons and text on the screen That's all done through the starter . Guri, another important folder, is a starter player, and inside of it, there's two more folders so many folders once called the Starter character scripts. And one is the starter player scripts in a row. Blacks. The player goes into the Players folder, and their character is actually the three D model of your character. You know, the one with all the cool hats. The Starter Player scripts only run once because of players only added ones. The starter Character scripts is different because when you die and respond, your character is created again, and all those scripts will also be created again. That's quite a lot of stuff to remember, so it's fine if you don't remember all of these folders over time, you're going to become a master and learn all of this because it will come naturally, just like breathing 4. Use Variables to Stay Clean: That's what guys were scripting. This is going to be the actual start of the scripting Siri's and oh, gosh, it's so hard. Just kidding. It's actually really easy. And today we're going to be learning about variables. A variable is pretty much text that has a value threat of variable. You need a name and value. The name can be anything. You're given all the power to truths. The name both great power comes great responsibility. Just be careful with your variable names. Make sure they're short and also match the value. You're also given all the power, the truth of value. That could be text. It could be true or false. A number Ah, bigger number. Ah, giant number. It can even be a table. No, it madden at the table you're thinking of now. What's the use of variables? It's just text that holds the value. It seems useless. Whoa, Variables. They're fantastic. Variables were used to organize scripts and store values. And staying organized is really important because once it gets to an organized, it gets harder and harder to script. Why would you want to make scripting even harder? Variables. Air used in every script you will ever see in your entire life. When you create a variable, pretty much what happens is a text becomes the value that it holds. So let's create a variable and Colin number, and let's set the value to five. If we write number, the script will actually read. It is five instead of number. So let's print the variable into the output so that you can see how it works. Bam! It's an imprint number. It printed. Five. I'm going to show you an example of how useful they are. So here we have some code. Now what this code does is a customizes the black. It turns it into a meteor PTSD flashbacks. Now, when you see here is that we're repeating game that works based on meteor over and over again. That's bad. There's a scripting rule called Dry, which stands for Don't repeat yourself. And right now we're breaking this rule because we keep repeating game dot workspace. Stop meteor over and over again. Now this is where variables come in. Recon. Stop repeating ourselves with variables. Let's create a variable. I'm going to call it part, but you can name it anything you want Maybe you want to go wild and call it matter formed from molecular Adams. Now let's make the variable equal to with the meteor, so game dot works based on meteor. So now we can replace all of the original game dot works based on Meteors with the variable . And it's pretty much the same script you remember. A variable pretty much turns into the value, and the value is gamed out. Workspace Stop Meteor and now we're following the dry rule. Variables also make it really easy. The change your script. Let's say we change the Meteors name to star. Oh no, we're going to have to go through every game. Doubt works may stop meteor and change it to gamed out workspace dot star, But instead we can just change the variable and it will change for all of them because we used the variable for all of them. So before I told you that a variable can be a number ah, bigger number, A giant number. Now I'm going to show you some more values that it could be variables could be text. This text can be anything you want it to be. Just make sure they use quotation marks to tell the script that it's text without quotation marks. The script will be confused, and it'll error. As you know, very bliss can also hold number values. Now. This could be any number. It can have a decimal in it. It can even be a calculation like three plus seven. And don't use quotations for numbers that's only used for the text. You want to hear a funny word. Boo Lean. This is just a weird word, and it means true or false for true or false values its text. But you don't use quotations for this. Variables can also be objects like a house or a sword, a script and anything you see in the Explorer. To get an object you can write game when your a game. You're starting at the Explorer so you can take gamed out works basic game that replicated storage any of those folders. Now, if you want to find a house that's stored in the workspace, your contempt game dot workspace dot the name of the house. Now, in my case, I chose a tree house, so all right, the name with the treehouse. Now make sure that the name is spelled the same way in the Explorer and the script, even capitals matter. If you miss, type it. You'll know because you'll get an error in the output. Look at this, I accidentally wrote an actual E and output told me, If you don't want to start a game, you can start it. Script when every typescript, the start location is the script itself and you could branch out from here. So if you want to get the thing that the script is inside of, you can type dot parents. So if the script is inside of a part in your typescript appearance, it will actually be the part you can even write dot parent multiple times to get the thing that the part is inside of so script would be the script script. A parent would be the part script up parents that parents would be the thing that part is inside of, and in this case, it's the workspace. There's also functions in robots. Now. These air really cool. It's pretty much a mini script in your script to create a function just right function variable and then two round brackets. Now, in between the function and the end is your mini script. I'm gonna put a prince in here just so you see how it works. You can type is many lines in here. If you want to turn it on, you just write the variable name and then two round brackets and bam. You could see every time we write the variable name. The mini script works. If you have a part of your script that you repeat over and over again, you should turn it into a function. So your code is cleaning, hearing under control. Now there's also tables, tables and roadblocks, or not like the tables in real life. Tables and roadblocks are written with two curly brackets, and tables are actually just a bunch of values Inside the brackets. You could store as many things as you want by separating them with the Kama. This could be any of the other things, like the text, a number you can even put a table in a table or any of the other values that I showed. I love variables. I should make a T shirt or something that says that, and soon you're gonna fall in love with variables to trust me. 5. Creating, Cloning, Destroying: What's up, guys? It's Mr Cool Teacher. Today, we're going to be cloning and creating objects from a script. This is a coolest thing. You could create so much with it, and it's really easy to look how easy it is to create a fresh new object from scratch. Just type in since Dot knew with your own brackets and two quotation marks at the end. Now, inside of the quotation marks, you can type any object you want to make. You know that list with all the items you can create anything from that list by just typing it's name. I like blocks. So let's create a fresh new black by typing parts in the quotation marks. All right, let's run the script. Where? What? Where is the part? Maybe it's in the replicated storage. Well, workspace, uh, this part just pranked us. Where is it when you create a new part, it doesn't exist anywhere now. To fix this, you need to set the parent of the part. The parent is a thing that the part will go into. I want to put the part into the workspace, so I'm going to type part. That parent is equal to gamed out workspace. Now, when we run it the parts right here. All right. Since the part prank this before I'm going to set it on fire. To do this, we can use instance on new again and take fire inside of the brackets. Now, let's set the parents of the fire to the part. So let's type fire dot Parent is equal to the part. Uh huh. It's on fire. Yes. You can also clone things that you've already made, which is really cool. You can use this for a map, changing script and other stuff. Now, I found this Dominus, and I want to clone it to get infinite. Dominus is this won't go to your roadblocks account in just days in a row. Black studio. I know it's sex, but this is so easy to do. He won't even believe how easy it is. You want to know how to do it, huh? Bam, That's it. Just type clone. It's so easy. Let's run this. What? Where is the Dominus? We got pranked again. We need to set the parent when we clone things, too. Don't forget to give the clone appearance or you'll get pranked like me. I'm going to parent it to the character so that it wears it. So I'm going to put it into the starter. Character scripts. Everything inside of the starter character scripts goes into your character so we can read script up parents and it'll be our character. We gotta Dominus were rich When you clone things, everything is the same as the original and even copies the things inside of it. So if there was a fire inside of it, the clone would be on fire to now. When people join the game, I want them to have the Dominus for a few seconds and then it's getting destroyed. Let's add a wait and then let's type colon destroy bracket bracket to delete it. Oh my gosh, have a dominant Where's my dominus? That's how to creeds, including objects. Super simple stuff. Just don't get pranked like I did twice 6. Customzing a Part from a Script: What's up, guys? It's me, Mr Cool Teacher. In the previous video, we created a black through a script. Now this block is pretty boring, but it doesn't need to be boring. We could go into the Properties menu and Testa Where to go. You know what no need for the properties menu were Scriptures. You could change every property from a script and I'll show you how this block will be a masterpiece. Now every masterpiece starts as a blank canvas. So let's create a new part using instance on new and parented to work space. Don't forget. I know you really want to change the color through the script So we're not going to do that . Just kidding. Let's do that To change any property first, you need to write the variable off the thing that you want to change dot the property you want to change. The variable that I chose is masterpiece on the property that we're going to change is the color. So you should write masterpiece stock color setting. The color is special. You can trust right light red. You need to write color three thought from RGB and then two brackets. This is weird, but this is what you need to type to create a color value. Now, inside of the brackets, you need to type three numbers. The first number is how much red you want. If you want no red, you can type zero, and if you want it to be completely red, you can take 255. The second number is green and the 3rd 1 is blue, and it's the same 0 to 255. Now I want to make this black purple there. Here's the easy way of doing it. Insert a part into the game, then go to the properties menu and choose the color you want when you choose. The color tells you how much red, green and blue there is in that color, so you can just copy that. No. One. We run the script. You could see that the part is beautiful. What's changed? The transparency to so to do this, let's say masterpiece dot transparency and transparency goes from 0 to 10 is visible and one is invisible. I want to make it 1/2 transparent, so weaken type 0.5. I also want to change to the material, the default oneness, plastic. And that's low quality material for this masterpiece. I want to make it glass. The material is drop down list and things and drop down lists could be changed by using text. Let's take Masterpiece Don Material is equal to glass since its text. You got to use quotation marks. I'm going to show you guys my precious Oh my gosh, I forgot to set Anchored. The true anchor just means that the part will stay in the same spot like Minecraft blacks, if anchored is off than it'll fall and get pushed around like real life and anchored is actually a true or false value. So I'm going to type Masterpiece that anchored is equal to true, so it doesn't fall from the sky. Now it's time to add the finishing touches. I'm going to change the size and the position to change these two units, right vector three dot knew and the brackets. There's three values, like the color three value, and instead of being red, green and blue, it's X Y and Zed. The X is a site decide position or size, the wise for up and down and the said is for front and back. What's hop into the script and let's finish this masterpiece. I'm going to grow the part on the X axis by for the Y Axis by 10 and the said by five. I'm also going to give it a random position, and that's how to turn apart into a masterpiece. It's pro tip time. We just learned how to set properties, but you can actually read properties to, so I want to find the material of this part. It's located in the workspace, and I named that chicken nugget, so we're going to have to get it by typing workspace. Start chicken nuggets. Now that we have the parts, we can read the properties by typing the properties. Name is an example. You can read the position by typing dot position through the material. You can type don material. Let's print the material to see what this chicken nugget is made of, and you could see that what chicken nuggets are made of plastic. Oh, this is one of those McDonald's is pink slime nuggets, so I want to position the masterpiece where the nugget is to do this. We're going to set the masterpieces position to the trick in Nuggets position. Now, when we run the game, you could see that the masterpieces right where the trick and negatives and you can even check. Let's take a look at the properties, and when you look at that boom, they're the same vowel. Now I challenge you to customize a part two and turn it into a masterpiece. You could make something like a dragon Grand Theft Auto six or a big red part I'll let you choose. 7. Use Events to Make Explosive Lava: lava. We're making lava today To make lava. You need to use events Now each item in a row Blacks has its own events. There's hundreds of events. How are you going to remember? Have you heard of Google? You type in whatever you want and bam, there's the roadblocks Wikipedia. And it's like Google. But for only row black scripting. This is what everybody uses. Let's get onto the Wikipedia and let's search apart because the lava is apart. The vents air usually at the bottom of the page. So key. Keep scrolling. Yeah. Yes, Mr More events parts have a touched event. The Wikipedia gives you a description of the event here. Says fired. When a part comes in contact with another part. Sometimes events even give you extra information. And here you could see that the touch dement gives you the part that touched the lava. This right here is the event we need to use for the lava. Okay, so let's create the lava insert apart, Mikelic. Cool. And now, when you touch it, I forgot the script. Okay, let's insert a script tow hook up in events. You first need to write the thing you want the event to be connected to. We want to connect it to the lava, so weaken typescript up, parent. Then you need to write the name of the event. The event is the touched event, so it's type dot touched. Every event also needs a connect function, and that's it. We have now hooked up a touched event to the lava. Everything in between the vent line and the end will happen when it's touched. Now what do you think's going to happen when we touch your I know? I'll tell you the answer. In 321 Nothing. There's nothing in between the lines, so nothing's going to happen, so we need to make it so that the player dies. Now, this is pretty difficult because we don't even know who touched it. But actually, the touched event does have a variable that tells you which part caused the touch. Prevent people like to call this hit, so let's call it hit. You can name it anything you want. It's a variable, so if you touch her with your right toe, it is going to be your right toe. If you touch it with your left knee cap. it is going to be your left knee cap to get the character from this weaken tape hit that parents and that will be our character. And inside of the character, there's an object called Humanoid So type dot humanoid to get that The humanoid is a special item that has all the players stats. It has the health and a lot of other things, like the walk speed. Now we're going to need the humanoid because we're going to change the health. So let's type hit out. Parent dot humanoid dot health is equal to zero. You see that we're using the property, which is health, and we're setting it to zero. No. When we play the game, you could see that it works. Now you're probably thinking to yourself, What the heck is that? If he thought parent, find First White. That's called an if statement. If Simmons Air used to check things to make sure it's correct. If a regular part lands on the lava, it will trigger the touched event. But we don't want regular parts to trigger it. With the if statement, we can ignore the regular parts, and we'll learn about that in the future, so don't worry about it right now. Now this love is kind of boring, don't you think? I want? I want to switch it up a little bit, maybe explode the player when they touch the lava. I know that lava doesn't explode, but I think it'll look cool. We can create a new explosion by using instance dot in your and now we need to customize it . We need to position it so that it's where the character is, and we're also going to parent it to the character so that it shows up explosive 1000 degree lava. I need to put a warning sign beside it. Okay, let's create another event just to get the hang of it. This one's cool. It's called the diet event, and it works with the humanoid only, Let's say you're making murder Mystery. Three. Actually, I think there's 1/3. There's 1/4 12 There's 1/5 of Okay, whatever. Ah, you can use the diet event to detect who survived and who got murdered. I'm going to parent the script through the starter character scripts so that we can get the humanoid easily because things inside of the started character scripts go into the character so we can typescript up parent to get the character. And then, from there we can get the humanoid. Now we need to hook up the died event to do that. Let's type humanoid dot died than the connect function that comes with every event. You know how there's a hit variable with the touched event. The died event doesn't have that so we can leave that empty Now. When the player dies, you can do anything. But I'm just going to print Ha ha! You died. It's a good thing we made the lava. Now we can die. And when you die the prince Ha ha! You died. You get made fun of every time by 8. Deep Dive Into Functions: What's up, guys? It's me, Mr Cool Teacher. Today we're going to be checking out functions these air the coolest things ever taught by the coolest teacher ever. Am I right? Introduced functions in the variables episode, and now we're going deep into functions. Now you can put anything inside of a function, and they come in handy whenever you repeats a part of your script over and over again. Instead of writing the 10 mines over and over again and copying and pasting them, you can turn it into a function and call the function with one line to call a function. You just need to rate the functions variable and two brackets when you call a function, everything in the function runs already already gives. If you remember from the Variables episode, the way to rate a function is by writing function, and then you need to give it a name. It's a variable, so it could be anything. After your variable, you gotta put two brackets and an end, and inside of the function, you can write anything your ones. What I'm going to do is I'm going to generate a random number to do this. We can type math at random. One common 10 that just generates a random number from 1 to 10. The first numbers, lowest attic and be in the 2nd 1 is the highest. Let's call the function by writing its name and two brackets. If you never call it, it'll never work. We just called it once with this line. And now let's run the game. Let's take a guess what the random number is going to be. I'm guessing that it's going to be a seven. Ah, it was a four. Since it's a function you can call it over and over again, which generate 10 random numbers. This time we're going with 10 random numbers. I'm still going to go with seven. That's my lucky number. There's No. Seven. Are you kidding me? Regenerated 10 numbers and No. Seven. Okay, right now, the lowest number is one in the heist is 10. Every time I want to make it so that you can give the function any lowest and highest number. To do this, we can add variables in our function. Let's call one lowest and let's call the other one highest. These actually don't have a value right now and we're going to need to give it to them when we call the function. So we need to give them a value. Here. I want to make the lowest 17 So let's type seven and the highest 17 Just type it into the brackets and separate them with Comma. Let's run this. Let's take a guess again. I'm going with seven. Seven is my lucky number. I had really bad luck before, but I'm really feeling at this time. What? How is it in hot seven? The lowest and highest was seven. It could only be seven. Just kidding, guys. It did print seven. Right now, the random number generated is locked inside of the function. You can only use it in the function. But what if you wanted to use it outside the numbers like Princess Peach? And the function is Bowser's prison. The Save Princess Peach. You need to return the number and functions. You can return a value. What that means is that the function call becomes the value that you returned. If you return five, the function coal will be equal to five and functions that don't return anything will be equal to mill, which means it has no value at all. So when our function, let's return the random number that we generate to show you how it works, I'm going to generate to random numbers one from fourth to eighth and another one from 10 to 20 now. Since he returns the number, we can actually add it. Subtract it. So I want to add. We added the two numbers a k a. The Princess peaches together to create a big princess peach. And as you see it worked, it added them together. Let's remove the return and see what happens. Remember when there's no return, the function cull is equal to nil, which means it has no value. What do you think will happen when we try to add to nil values? Here's a hint the script will air because you can only add numbers. You can return strings, tables, a whole bunch of values, not just numbers. So that's what a function looks like when you go deep into them. Functions are fantastic, but hold up before you go. I dare you to create a function that lets you give it to numbers, and then it adds them together and prints it out. If that's too boring for you, you can do whatever you want, but just practice practice makes perfect. 9. All About If Statements: Who are you? Oh, you're here for the if statements. Okay, come on in. It's me, Mr Cool Teacher. I know you've been waiting for this episode, so let's not waste time. What's running straight into the if statements if statements air used to check things If you remember from the Events episode, we use an if statement to trick that, the part that touch the lava was a human. You can check anything in an if statement to you can check it for player owns a game. Pass you contract. If apart exists or not, you can even check if someone has enough coins to buy an item in your game. Let's make our first if statement to write an F statement units rate if then end. The underlying is where we write the condition. The condition is what we're going to check. Remember, you can check anything you want your hair for an example. This is gonna be boring. Bullets check if one plus one is equal to three. When your script one equal sign is used to give a value to a variable here, we're not giving a value were actually checking a value. So you need to use to equal signs. If the condition is true, it will run everything inside of the if statement. But if you're a pro at math like me, you'll know that one plus one is equal to two, not three. So the condition is actually false when it's false. That means the if statement is going to get skipped. Let's check out some more examples. Remember that when the condition is true, the if statement runs and when it's false, it gets skipped. All right, I'm gonna shoot some questions that you are answered them quickly. If the condition is 10 is greater than 100. Will the if statement run? Really get skipped? Thats one will get skipped because 10 is less than 100. Not greater. Now. What if the condition is 10 is less than 100 K? What's gonna happen here? Thats will run because it's shaking If 10 is less than 100 that is, if the condition is five times five is equal to 25. Well, the if statement run or get skipped, thats one is going to run because five times five is equal to 25. That's right. I did that in my head. I'm a pro mathematics Kaymer. Okay, this one. If the condition is true, will the if statement runner, will it get skipped? Okay, this one is going to run for sure, because the condition itself is true now What? What if it's false? What if the condition is balls? Okay, you should know that it's going to get skipped because if statements only run when it's true, You guys want to see a cool thing, huh? You want to see something really cool? You can combine conditions together by using logical operators logic. There's two logical operators when his end and the other one is, or for the first time around, let's combine them using end. So let's type if 10 is less than 105 times five is equal to 25. When you use an end, you need to conditions and both of them need to be true. If only one of them is false, the if statement is going to get skipped. So let's figure out if this if statement is going to run. The first condition is tennis less than 100 and that's true and the second condition is five times five is equal to 25 which is also true. A. They're both true. So the if statement is going to run. What if you want to conditions, but you want the if statement toe work, even when one of them is false. For this, you can type or when you use, or only one of the conditions need to be true. The If semen right here has the conditions, one plus one is equal to two or one plus one is equal to three, so you could see that the 1st 1 is true and the 2nd 1 is false. Remember, there's an or here and or doesn't care if it's false, as long as one of them is true, that's good enough. The only time that if statement gets skipped within or is if both of the conditions were false. If you understood all of that, you're already a big brain scripter. I think that's enough testing. Let's do some fun stuff now. You know that the if statement gets skipped when it's false, but when it's false, you can actually use else and else if to make the if statement through something else. So let's say you're making murder mystery 17 and you want to give the murder of the knife, the sheriff, the gun and the innocents. Nothing to do this. We're going to have to use else. If Abdullah Bhai says, Ah, what was that? That was just the spell to create an if statement You're a wizard, Mr Cool Teacher. The if statement here is checking if the players role is murder and if it is, then we give them the knife. But what if they're not the murder? Instead of creating a brand new if statement to check, we can use else if role is equal to sheriff. This is pretty much an if statement, but it's inside of the original if statement. So it's a little more organized and else if gets checked whenever the if statement above it is false. The condition here is role is equal to sheriff. Guess what? That's true when it's true, it's going through and everything in between it and you can even add multiple else ifs. So let's add one more for the innocence, and what happens here is the script reads it as over the first. If statement is false, let's go to the next else. If if this is false, too, then we move to the next one. The script starts at the top of the if statement and slowly goes down until one of them is true. If none of them are true and nothing happens, there's also else when the script reads the original. If statement in its false it moves to the else If But what if all of those air false, too. That's where the else comes in when everything is false, the else runs a great use of else would be. When you're making a shop when they click the button to buy, the first thing you want to check is if they can afford it. If your money is greater or equal to cost than they have enough money and you can use an else to check if they don't have enough money, Ellis is pretty much the opposite of the other. If statements, that's pretty much it. That's it, for if statements we're done with. If statements now hopping through a black studio and start practicing practice makes perfect 10. Having Fun with While Loops: What's up, guys? It's your boy, Mr Cool Teacher. We're checking out while loops today. What oh, I look does is it repeats her code over and over again for you. One use of while Loops is to create a looping many game like the one in Piggy murder Mystery to Arsenal and a lot of other games. The loop in those games is start in the lobby. Get teleported into the game. You probably end up dying. Are least that's me cause I'm pretty bad at the game with. And then the round ends and that loops over and over again. And they did that with a while. Loop. Now, if you're a big, big nube, you would usually copy and paste, but no more. While Loops let you loop your code over and over again so you don't need to copy and paste anymore. You can make one billion parts and fryer computer with the while loop, and it's so easy, so let's right the while loop in a script. The first line is wild, true do, and you need an end now to test it out. Let's use incidents Dot knew and let's create a brand new parts and let's run it. You should always put awaits inside of a while loop or else it'll crash. Let's run a now. There you go. We have generated infinite parts. It's so hard to move. I can't move. Okay, we're back in the script and I'm going to tell you something Cool. You know, if statements while loops air pretty much repeating if statements, you know how we wrote wild, true do that runs for infinity and beyond. But what if we want to stop it, weaken swept the true with the condition so that we can stop the loop when we need to. Let's make it stop at 100 parts before we make the condition we need to track how many parts there are to do this. We can use a variable, and for each part we add, we can add one to the variable. So if we have 10 parts, the variable is going to be equal to 10. Now we're going to have to set the condition. We want it to stop at 100 parts, so our condition is going to have to be part count is less than 100 in a while loop. This would. Meanwhile, the part count is less than 100. We create another parts until it's equal 200. The condition gets checked every single time the loop runs, so when it runs, once it creates the part than an adds one to the variable, and then the condition is checked again. If the condition is still true, the while loop is going to run. And when it reaches false, that's going to exit the loop while loops air. Pretty cool and useful for making many games now loop over and over again. Soon we're going to learn about four loops. You can use four loops to create timers. You can use it to go through every value in a table, and they're really important when scripting, yeah. 11. It's For Loop Time: 321 You see that timer? You can make timers with four loops? Yeah. Hey, you can use four loops to do things. A set number of times. You can make countdowns. You can go through all the players of the game and a lot more. There's two different types of for loops one for timers, which is called a numerical for and another one to go through all the values in a table, which is called a generic. For the startle, let's do the new miracle for all rights to write a numerical for units type for I is equal to underscore, underscore, underscore do and then an end. The eye is actually a variable, so you can name it anything you want. Now we need to replace all of the underlines. The first underline is the number that you want to start at. The 2nd 1 is the number you want. The loop to end up in the 3rd 1 is how much you want the loop to change by. So let's type in four for the start. Tend for the end and two for the change. So in this case, it starts at four runs, then it adds to so become six loops again becomes eighth loops again becomes 10 which is the end number, so it stops after four loops. Now the i variable. What is it? What is this? I variable? The eye is actually the number that the loop is on its equal to the 468 10 that we just went over and you can print it out to see for yourself. No, let's create a countdown to show the countdown on the screen. Let's toss the screen gooey into the starter, gooey, and then let's sauce a text label into the screen. Gooey. Now we have a text label on the screen for this. We're going to need to use a local script because things in the Starter gooey years, local scripts. We'll learn more about grease in the intermediate scripting course. Now let's write this script. The first thing we need to do is we need to get the text label. Since the local script is inside of the screen gooey, we're going to have to typescript out parent to get the screen gooey and then that text label to get the text label. Let's make this countdown start at five and count down to zero. This is what the four loops gonna look like since we're counting down. The third number is going to have to be negative. If it was positive, how would it go down in the for loop? We're going to have to change the text toe I and we're going to have to add a weight that lasts one second. Now let's run it. The countdown starts 543210 Remember that you can do anything in the loop. Instead of making a countdown, you could create parts and other stuff like that. Now it's time for the generic four loop. This is way different than than the new Miracle one. The numerical for loop has a start end and a change. This Look at this. What is this? It looks pretty complicated, but by the end of the video you'll know how it works. Let's create a table. You probably forgot what a table was because we barely used it. A table is written with two curly brackets, and you can put text numbers true or false. You can even put a table in a table. Generic four loops need a table. So let's create one. My first value is going to be Velika Charger for second value Al Khuzaie and third value. A little a little. The generic for loop pretty much goes through every single value in the table for you. Okay, let's type the loop. You'll have to rate for ICOM, Avi in pairs bracket bracket do. And you need to replace the underscore with your table. My tables variable is tab, so I'm going to write Tab and that's it. Now the four loop is gonna go through every single value in the table. You know, the I in the V. Those air actually variables the eyes. The current position and V is the current value. So when the loop is on the first value, I is going to be equal toe one and V is going to be equal to the Velika. Josh. Just refer The eye for the second value will be too. And the V will be equal to Al Cacao. Cofer, look at these innocent parts. Let's make all of these innocent parts kill you. So to do this, let's create a table. All right, all right. Inside of this table, we're going to put all of the parts that we want to kill you. So I made a list of all of my parts, and now it's time to use the for loop to go through all of them. The V variable is the value, and the value in this table is the innocents part. Now, since it's the innocent parts, we can use the variable and hook up the touched event to it. And now we're going to take the script from the lava episode and hook it up to the V variable. So what we're doing here is we're going through every single value in the table and we're hooking up the touched of into them. They look so happy. Let's give them a hug, Theo, or you don't worry, it's role blacks, you can respond. 12. How to Read the Roblox Dev Wiki: Hey, guys, it's me, Mr Buff Teacher. Today we're going to check out the Wikipedia. We've actually already been there before. I smell events. That's right. We use the Wikipedia in the Events episode, but there's a lot more on the Wikipedia that we're going to explore today. The Wiki has information about every single object and service the sites. Developer dot roadblocks dot com and to navigate the wiki, you can use a search bar. You can type any object their service. Let's check out the good Ole User Input service. No, if you don't know anything about user input service, that's good. That's why your on the whole Wikipedia, Jack, if you don't even know what it is, you can always read the description. The wiki gives you a description of it, plus the properties, functions and events and sometimes even a few other things. Let's read the description to find out what user input services the user input service. It's a service used to detect and capture the different types of input available on a user's device. So we just found out that the user input service allows us to detect when a player clicks a button on their mouth or few board even a tap on their phone screen and stuff like that. Now let's check out the properties, properties there, stuff that you can change and or read. We changed properties in the customizing episode. If you remember, you should remember. Oh, my user input service has a lot of properties. It's fine, and we're just going to check out a few. We're not going to spend 30 minutes reading properties. Let's check out this property. It's name is mouse enabled, and you can actually click on it to get sent to a page with more information about that property so we can see that the value of the property is a bull in which is true or false. Other properties can have different values. If you remember when we customize the part, there was the color value. There was a number value for the transparency. There was true impulse for the anchored. There's a whole load of different values out there. Some properties there special because their read on Lee, which means you can change the value, but you are allowed to read it. Let's check out the description here. It says this property describes whether the users device has a mouse available. This is true when the users the base has an available mouse and false when it does not. So let's use this property in a script. Since user input services a service, you'll have to type game, get service and inside of that you think the services name, which is user input service. There's also a lot more services, not just user input service. So you should explore the wiki and maybe you'll find some cool stuff. Cool like me, Mr Cool Future. Now that we have the service, we can use the properties since mouse enabled is a read only if we try to set it to something else, you'll get an error that says that you can set the value. So let's just read it and let's print it out. If it's true, that means I have the mouse enabled. And if it's false, that means I don't have it enabled. Yes, I have the mouse enabled. It's right here. Let's check out another property this time much sick one that's not read only because I want to set the value of the property to see what happens. The one that I'm gonna change is called mouse Icon enabled. The description says, that you can use this property to make the mouse visible or invisible. You could also see that it's a true or false value, and I'm going to set it the false so that the mouse is invisible. We're gonna need to use a local script through this, and the first thing we're gonna do is we need to get the service. I'm going to set the value to false Now. When you run the game, you can see where you can't see that your mouse is invisible. You also have functions, functions air like commands. It does something for you. User input service has a lot of functions. Let's check out the get keys, pressed function. The description here says that gives you a list of all the keys that you're holding down. The wiki also shows you what the function returns. The get keys, pressed function returns in array, which is just a list. This list contains all the keys that you're holding down. Since it's a list we need to use a generic for loop to go through every single value in the list. I'm going to print out all of the values every second, so you can see how it works. So I'm holding the space key, and you could see that a printed space. I'm gonna take my hand off, and now it's gonna stop. You can also hold multiple keys. I'm going toe hold D a b, dad, and you could see that a printed all three of those keys. User input service also has the is key down function. This one tells you if you're pressing a key, if you're pressing it, it'll return true. And if you're not, it'll returned. False. Let's use it in a script. This function is actually a little difference. Right now. The function doesn't know which key you're gonna check. Is that the A key? Is that the space bar? To tell the function which key you want the check, you need to tape it inside of the brackets. It even tells you that on the wiki back in the script, I'm gonna check if the a key is getting pressed. So I'm gonna type in nam da kiko dot a In the brackets, it's printing false because my finger is not on the a key. Now I'm gonna press it and it's printing. True, let's check out events. Some useful events that user input service has is input began. This event fires whenever you press any key, and that also gives you extra information. It gives you the input, which is the cue pressed, and it also gives you the game processed event, which isn't too important right now. Let's set up the event just like we did in the Events episode User Input Service than the events name, which is input began. Since the events gives us the input and the game process event, we need to add those variables in the brackets so we can use them now, which time that someone presses a key. This event is gonna fire. We can get the key there just pressed by typing the first variable I chose. Input is the first variable daki code, and I'm just gonna print this out so you can see you can see that it printed out each key that I pressed. There's also input ended, which is the opposite. This event fires Each time you take your finger off of the key, you can use input began to tell when the player press the shift key. If they pressed shift, you can make them run and then you can use input ended to make them stop running. You should explore and play around because that's what scripting is all about. All right, that's it. I'll give you some of things to explore. You can check out marketplace service. That's what you need to use to sell game passes and developer products. You should also check out the text button and Tween service. If you're adventurous, like Indiana Jones and that's it, it's over. 13. Make Your Own Game!: Hey, we made it. We survived. Here's your diploma. Now the best way to learn to script is by creating your own games. The games that you should make should be very simple, like Think of the most simple game taken, even think of. That's the game you're gonna make. But it's not always gonna be a simple. Once you make more games, you're gonna learn more, and then it can get way more complicated. Just don't go too crazy. This starts. Keep it simple, create a knobby, then move on to a basic simulator. Take your time. Now there's a challenge for this course. The challenge is to create speed run. It can't be speed run without speed, so the first thing to make is a speed pad. You can create this by hooking up a touched event to a parts, and whenever they touch it, you increase their walk speed. Whenever the player falls to their death, you're gonna need to have a part there that kills them whenever they touch it. Whenever the player finishes around, you need to tell Put them to the new map by using C frame or a reason to go oversea frame in this course, but it's pretty much just the position of a part. You can trick it out on the wiki developer dot roadblocks dot com. It's a little advanced, so no see framing in the beginner course. Those three things are pretty much the entire game, those air the basic scripts needed. But you know what? That's pretty boring. Don't you want to add some more things? Well, you can. You can use whatever you've learned to create anything. No, I linked a few months that you guys can use so it can focus on the scripting and not the building. The maps there on the class Projects page so you can get it from that. And that's it. It's over. If you're confused about something, trying to re watch the videos and experiments in real black studio writing scripts yourself in real black studio makes you learn way faster, and if you still don't understand, then you can message to me. It's it's over