If you want to know how to script on Roblox in 2018 then this is the tutorial for you. If you’re looking on Roblox How To Script but finding it hard then watch this video, it’s tailored towards beginners! In this video we go over all of the Roblox Scripting Basics in detail so there’s nothing you won’t understand.
What is scripting on Roblox? Scripting is writing code which tells the game what to do so that things can be done automatically without you having to manually run games. All of the games on the front page of Roblox are scripted which allows them to work and entertain players in many different servers. Scripting makes games more interactive.
Subscribe to my YouTube channel for more scripting videos:
Become a Channel Member for exclusive perks and to support me!
► Watch my full beginner scripting series:
Got video suggestions or feedback? Contact me via my website
Roblox username: alvinbloxx
The music in this video is licensed from Epidemic Sound
#AlvinBLOX #HowToScriptOnRoblox #ClickMeForMoreTutorials
Learn how to use Filtering Enabled with this new tutorial: “Roblox Filtering Enabled Tutorial – Spawning Parts from GUI”
in this video I'm gonna be teaching you how to script on roblox for beginners I'm going to show you all of the basic things that you need to know about roblox scripting let's get straight into it alright so welcome back to another video my name is ivan blocks and I've been on roblox for almost seven years now and developing for nearly 5 years so I know how to use roblox studio platform and I know how to script and I want you to script as well scripting is really really awesome it lets you make your games more interactive because you don't have to be there making it work you can make your games work for you and then once you know how to script you can make great games and you can make money from those games so if you want to do that then make sure that you follow along and in this video I'm gonna show you the basic concepts of scripting and what you need to know so let's get started then and this is the roblox studio if you don't know how to open it up then if you have a plate of roblox game before the roblox studio will be installed on your computer alright so you just need to do a search on your computer for the roblox studio and then you'll be prompted to sign in and then if you click on a base plate or press ctrl n you'll be brought to this screen alright so to get started with scripting we're going to insert a script into the workspace ok so let's insert a script we're going to right click on the workspace hover over insert objects and click on script now I'm just going to show you how this all works now we've got our ribbon bar at the top of the screen that's where all of our tools are a bit like a Microsoft Word we've got all of our tabs at the top home model terrain test View plugins and the script menu home is useful when you are making parts when you're building because you've got access to the tool box where you can insert models into your game just like that you've got the parts you can insert parts into your game and you can change the color of them you can change their material etc so that's the home tab now you can find more building tools in the model tab you can see we can move our parts we can just click on a part we can move it with a move tool we can scale it to make it bigger and we can also rotate it so I advise you to have a play with that but that is the ribbon menu we can do terrain which we might learn about another tutorial you can test out your game click on the play button to launch an environment with your game to run scripts you can also run scripts without having a player in the game and you can also have a view here now this is what we need to focus on right now our view is where we're going to open up all of our panels okay so this these things are panels okay the output here the properties tab the explore tab these are all panels and to open them you need to go to the View tab so you can see you've got properties and Explorer now Explorer is where we will find all the parts and objects in the game environment all right so we're going to make sure that that's opened up and we've also got the properties tab here so make sure that's opened up as well that's where we can edit parts for example the brick color I can change that from the properties window all right so in our script we're just going to delete these these parts first so just select them all right so we've got our script and I'm just going to show you the basic parts of roblox scripting now so the first thing you need to know are variables okay variables that they hold piece of data now if you use any other programming language before you will know what they are but if you haven't it's used to store data okay so for example we can have a variable called hello okay and we could set that value to 50 all right now let's have another variable and we're going to call it bye all right bye equals 20 now if I wanted to add these two variables together these two pieces of data if I said print okay print what this will do is it will print a message to the output or it will put some text in the output window hey the output window you can find it by clicking view and output this is where errors will be reported from our scripts if we've done something wrong or if you want to send messages to make sure that something has happened and it's run correctly all right so when we say print and let's just put a string inside of here a string is a piece of text or some words so you can say print and then in the brackets in the speech marks for a string we can say hi there all right now let's go and run this all right we're gonna press the Run button if you don't see the one button just click that little arrow underneath the run and select it but you can see it says hi there all right and it's printed hi there to the output so that's how you do printing so if I want to add these two variables together you can say hello plus Phi okay now let's run this and you can see we get 70 all right we didn't get hello bye it didn't print hello bye out it printed 70 now that's because hello and bye have their own data inside of them okay so hello has the number 50 and by has the number 20 attributed to it okay because we've defined the variable here okay so we've said give by a value of 20 and give hello of I or 50 so we're printing hello plus bye so imagine we're adding the values of these variables together so 50 at 20 all right so we've just add two numbers together basic basic maths there all right so that's how you use variable that's how you set up a variable you give it a name you give an equal sign and then over here you say what it would be what you want to store you can store lots of other things in variables we can store boolean x' so my variable equals true okay or we could say my variable equals false a boolean value is something that is true or false it can either be true or false it can't be anything else or you can also store a string a string as I said is a piece of text hi there this is a string you can tell us a string because it's got speech marks around it and it's also purple and so that tells us a string now if we just print my variable it's going to print hi there this is a string okay let's try out then I click on the green Run button hi there this is a string and it printed all right so you can see how we print things to the output now when we're making games we will print variables often to make sure everything's running fine and we want to test our game out so that's variables okay and what we're doing printing we know the printer variable okay or we can print text so if I just wanted to actually print the words my variable not the not the actual value we can put this in speech marks to show that it is a string okay we'll play the game look how to click the play solo button that means that my character will be inserted into the game environment but you can see it's printed my variable because we told it to to actually print my variable not the value of it but if we got rid of the speech marks and we run it again you can see it prints the value of the my variable variable which is higher this is trim so that is printing and how you print things to the output as well as variables now variables will be used when you're making games to store bits of data for example in the murder in a murder type game like a murder mystery or the mad murderer if you haven't played those games before you would have to you'd have to store the name of the murderer who's the murderer who's the sheriff for example if you're in jailbreak you'll have to store a number and that would be how much money you could get from the bank the maximum amount of money you could steal from the Train for example so variables are used all the time in roblox for making games and it is very very basic but very is you've got to know it really because every game will use it so that is a variable let's just click on stop here and that will just kill the game environment and send us back to this free roam mode okay now let's move on to the next part which is properties okay now properties are everywhere in roblox now there will be in parts they'll be in scripts any object in roblox will have properties now you can see we've got the properties tab down here okay now let's go in insert a part into the game okay we've just clips on the part button in the tab and that's inserted apart for us okay now you can mess around with this part whatever you want but let's look at the properties tab alright we've got lots of different options here we can change the brick color we can change the material we can change the reflectance we can change the transparency lots of different things to change these are all called properties the transparency is a property the color is a property of that part okay the name is a property we can change this parts name to brick if we wanted to we can change its orientation how its rotated okay we can let's just make this not transparent we can change the orientation which is the rotation we can change the position okay we can change it with the move tool or we can just change it from this property here lots of different properties which we can change okay now you see that we can change them manually but we can also change them via a script and I'm going to show you how to do this but let's just go over some of the basic properties of a part okay because you might not know what they're for the color and the material are quite obvious they are the the material is look if I change it you can see the different material names reflects how it looks let's just keep a pebble and the reflectance is how it will reflect the Sun off the part and the transparency obvious self-explanatory now the class name is what type of object it is now we can't change that because we know that it's a part and if we would have asked this script its class name is a script and the part is a part because that's what roblox our set is soo the name of the part we can change that the orientation is the rotation of the park it has three values because it's made up of something called vector three and we'll come to that later on in this tutorial but it's an x y&z value and that makes up the orientation of the pot okay the parent what the parent is is basically what this part is inside of so at the minute it's inside of something called the workspace will also come to that later on and so if we were to put this part inside of the script okay the parent is going to change to script all right there we go change to scripts because it's now inside of the script it's now a child of the script but let's put it back in the workspace and there we go it's changed back to workspace the position that is also quite self-explanatory its whereabouts is on the map the rock velocity and velocity will not that's quite advanced you might come back to that later on but it's basically about how it travels how quick it travels if you were to move it all right so let's move on to behaviors now okay so we've got anchored now anchored if I show you this this pipe if I move up into the sky and I set the anchor property to false and I run the game the part is going to fall out of the sky all right there we go it fell out the sky but if now I set the anchored property to true all right there we go it stays in the air so that's anchored and the same thing with can collide here when can collide is set to false it means that anything can go through the part but if you have can collide set to true it means that the part will collide with other parts and other objects and it will use physics okay and so that's all you need to know really another one is locked that means you can't touch the part or edit it or select it which is helpful if you want to select a number of parts but you don't want to select some others so that is the locked property now these are quite advanced and we'll get to that later on except for the size which is also vector three and we'll get to that in another part of this tutorial so their properties but you want to know how to change these properties automatically from a script right well it's quite easy let's just get rid of this variable which we just worked on and let's look at properties now clear properties by the way this is a comment and it's green and that tells you it's a comment and we started with two hyphens now when it's a comment when it's green it means that the script is going to ignore it a case a note for you so that you know what you're doing and it's just a little reminder so I like to use comments I let me know you know when I finished when I finished doing something I want to pick up another time I can write comment to tell myself where I got to and what I'm gonna do next so the script totally ignores it it just allows us to have some notes so we want the change of property now very very simple we need to first reference the object we want to change okay now referencing is how I like to call it it's basically getting apart getting a part which is nested somewhat from the script okay because we don't know how to get this part okay which they want to change the baseplates property well we can't just say baseplates okay because we don't the script doesn't know where this base plate is held now I'm going to tell you something about how roblox works here now we've got the Explorer here and basically we have lots of things here okay they're called services but each service has a different role okay so workspace is where parts are stored okay and parts bricks models all of the buildings in your game that's where they'll be stored okay for you to see them if you want to interact with the brick if you want to touch it and you want to see it in the game world it'll always be in the workspace all right let me just prove this to you let's take this brick and let's move it to server storage it's gone okay we can't interact with it anymore let's let's put it in the starter GUI it's still gone starter pack gone start to play it go on sound surface gone chat gone we're lighting gone players gone replicate storage gone you see that they're gone they're not they don't show up unless they're in the workspace alright so that's where parts go if you want to see them for example if we have a map in a game which you don't want to have loaded in yet but we might load it in another time we can just keep it in the server storage okay but the workspace and the server script service and the server storage they are in the server okay now let me tell you how roblox works now when you join a roblox game you are called a client okay and a client is someone who's playing on their computers and connecting to a game server now let's just take a look at a game for example okay so this is jailbreak it's the most popular box game if you didn't know but jailbreak let's take this for example when we are going to play jailbreak and we click on that big green play button we are the client and we are going to connect to that game okay now every game which you join will have something called a server okay now we have servers here and there's gonna be loads of servers okay which you connect to you're going to connect to one of them alright and in this server is where all the scripts are run alright and you're just connecting to that game as a client and so when you connect to that game you start talking to the server the client your computer starts it connects to the server and starts talking sending sending messages to one another and saying I want to join this game load me in and the server will load you in and keep communicating okay so your client will tell the server when you for example press a key okay when you press the W key your computer is telling the server on roblox's end which houses all the game and all the scripts and everything nor the buildings I'm your player the client will tell you the server to move your player because you're pressing the W key which makes you move forward so whenever you're sending keyboard input from your client it's going to the server and so we have some services are in the server right such as the workspace because that's where all the scripts and the parts are held and some are only client ok for example the starter GUI and the starter pack and the starter player they are all on the client ok they're all on your computer on your roblox game you just don't see them but that's how we have the GU eyes on the screen there will in the start they start to GUI your tools which you use to play with for example a sword that will be in your starter pack and start a player is where some scripts might run but we'll get to that another time it's where scripts can run on your client so we have the client talking to the server and it's all good and we have the workspace the server script service and the server storage and the lighting I think which are on the server there servers end and they are there basically because if they're on every client okay people can lag anak and it would be too powerful for one player to run all of this on their computer so we use servers you connect to a server part scripts and other things I want that server we just connect to it so we're able to see them because a game usually has multiple players the server will have multiple clients connected to it okay and so when one client does something for example move their character the server will see that and we'll update the game for everyone else taking everyone in sync so the server manages every player make sure everything is is working together and make sure everything's happening at the same time for everyone so that's a simple way of saying it but the workspace is where parts are stored and server script surface is where scripts can be stored they can also be stored in the workspace makes no difference and the service storage is where you can store parts which you don't need yet in the server it's always good to saw your parts in the server anyway because it means that people well people can can export your game we might get to this later on I'm not sure but basically people can exploit your game when they run a cheap like cheat engine on the computer or something like that which edits the game and then the server will see that change and will edit it for everyone else and because filtering enabled isn't turned on but you might get to that another time I've got a filter enabled you to on my channel if you want to see it go to the link in the top right of your screen so we're going to just deal with the workspace for now we're going to deal with changing the property so to reference an item in the workspace we can we can say game ok because all of these services are in something called game ok our game we just call it game and then we want to specify the service service I can't say it but we'll say workspace ok because that's where the parts are stored and then we can say brick faceplate okay so we've got our base plate you can see how the script recognized that the script saw the base plate as we're typing it we know that we've got the right place we've got we've got the right base plate now so we can change it see by specifying which props you want to change so you'd say dot and then we can choose the property you can see you've got a list here of properties we can change so let's go and change the color property okay now if you want to change this color property we have to specify a color so to do that we have to say brick color dot new open bracket close bracket and then inside of these brackets in speech marks we can actually say a color now the color has to be correctly spell and it has to have capitals correct and everything to find a list of colors you can just go to the base plate and click on brick color and then you get this palette so just hover over color I new get its name so new yellow we'll call this one with the capital n and the capital wife and new and yellow we have just changed the base plates color using a script now let's go and test this game out with me click on run and hopefully the base plate changes to yellow I'm going to wait for it and it will take a little while to load there we go oh we got an error and the error is bad argument number two to color number three to color color through expected but got a brick color now this is because we selected the wrong property we selected the color property not the brick color now in roblox where you want to change the color you can either choose it from an odd RGB value red green blue and you can actually select one like this or you can select a predefined color called brick color now I like to always use brick color so I'm going to say brick color like that okay now if we try it again it should work there we go it changes to bright yellow but what if you wanted to use a custom color well you can do that you can just use the color property like we did before but instead of using brick color we have to say color color three okay because colors are made up of three values RGB red green blue and then we say dot from RGB because we're getting it from red green blue and we need our three values of red green and blue so let's do two five five zero zero because we want it all to be read and we don't want it to be any other color so let's run it again and it should go totally red there we go so we've just changed the base plates colors property by using color three and brick color so there's two ways to do that let's change another property let's change the transparency prophecy so I'm just going to get rid of the dot color and I'm going to change it to dot transparency game dot workspace base pay transparency equals one all right now what do you think is gonna happen when I set it to one because of the minute it's set to zero and it we can see we can see it all right now what what do you think will happen if we set it to the other end of the spectrum and one it's going to go completely transparent now it's still there we just can't see it and to prove it I'll go into the workspace and select it you can see that it's selected because we've got these little blue outlines it's just that we can't see it because it's totally transparent now let's go and take the slider and start to drag it all the way back you can see that we can start to see it again before it becomes fully opaque that's the transparency property and that's a number of property you see we we controlled it by a number instead of a string or brick color now let's go and try and change the anchored property okay they split the anchored you can see it's got a checkbox so we know that it must be a a boolean value so either true or false so remember anchored means whether it can fall out of the sky or not now we want it to be anchored stuck into the sky it's stuck in the air so we can just say true so yes we want to anchored so true now let's run this and it shouldn't move it should just stay in the air there we go now let's go back to our script and change it to false and run again and the base plate is going to fall out of the sky now where Smith falls out of the sky once it heats once it hits a certain position it will just delete itself and you can see it's it's been deleted from the workspace now you can change this in the workspace there's actually a property in the workspace I think it's here yeah it's called fallen parts destroy height and if we change that to maybe 3000 that means it's going to have to go down 3,000 studs before it deletes now just four just so you know once stood is it's this site is this small okay so the distance between one store to another is that much so if you thinking 3,000 studs it's gonna be quite big all right let's try it again let's see if it good if it stays in the air any longer okay so it should stay in the air six times as longer because we said it's in – 3,000 and watch it's been deleted from the workspace when it fell all right so that is how you do the anchored property I'm gonna let you experiment with some more properties of your own so let me know if you discovered it any new ones in the comment section below alright let's move on to the next part of the tutorial and the next part is going to be positions make sure that you've given me a thumbs up so far and let me know if you're enjoying it in the comments as well okay so in roblox when we want to change the position of a brick we can just move it around okay we can also use the Move tool if you want to move it on a straight line or if you want to move it or pull down now when we're moving this the position property is always changing let's have a look at that position property okay so we can see at the minute it's set to minus seventy thirty five point four five and minus one hundred and ten point four to five now this position property is made up of three values okay x y&z all right each value representing a specific direction now which direction does it go in well that's a good question now we can open up the we click on view and we can open up the display access to see which direction each one goes in now if you look down here the display axis is saying the green line is going in the Y direction the red line is going in the X direction and the blue line is going in the Z direction okay so if we move it with the red arrows with the Move tool to get the move tool you can just click on home and then move and select the pot when we move it you can see that the first value the x value here is changing now it's decreasing actually it's increasing because it's a negative number when we move it to the left and it's decreasing as we move it to the right that is the x value now if we click on the arrow here that will open up the x y&z values when I move the Y value because it's the vertical value you can see it increases I want to move it down it decreases I want to change the Zed value when we move the boleros when I move it to the right you can see it starts to increase when I move it to the left here it starts to decrease tartes to decrease yeah all right so we can move our part around and these values all change but the position is made up of three values x y&z now if we change all of these values to 0 0 0 the part will go right here and this is the exact middle point of the game world and as we move each arrow the different value corresponding to that to that color as you can see on display access changes now we can change all three values with the script and this is where something called vector three comes in now vector 3 is basically x y&z ok it's three values which represent the position so one we want to change the position property base plate dot position we can use vector 3 vector three now one more to move it to a certain position we can say vector three you open bracket close bracket and we will put our three values inside these brackets now remember that when we're putting these values in for example zero zero zero the first value will always be treated as X this way you will always be treated as Y and this one will always be treated as Zed okay now let's move off brick to a position over here okay now let's have a look at this position it's – 200 eight point six in the x-axis to point two in the y-axis and one hundred and eighty nine point zero to five in the z-axis okay now let's take this position these three values and let's paste it into our scripts okay and make sure they're separated by a comma now let's move our part somewhere else and let's run our game and this script will run now look over here where my cursor is now this part should move over there okay to the position which were you specified in the script now what this is going to do is the script is going to update the x y&z value and the part will move accordingly to that position now we just got that vector3 value whoops it also we didn't want to do that because we're actually moving the base plate instead let's change the brics position the brick aimed at workspace dock brick we referenced the wrong part and let's make sure the the base plate is anchored and so is the brick so it doesn't form all right let's try it again so yeah what's the cursor and there we go it's moved all the way over here to that position the script changed the x value the y value and the Zed value and it went over here so you can keep changing these values and the part will move for example let's change the Y value to 50 and it will move higher up in the sky if we made this a negative number it would go down and the same thing would happen when you moved it if you move if you change the X and the Z values okay let's change it to there's fre to 100 and it should have moved over there yeah it does and we can see the direction in which it moves by using the display axis all right so if we change the z-axis to negative 100 it should move right which it did no doesn't we need to make it positive sorry it needs to be positive and it will move right let's change it to 200 there we go it moves right and we've change it to minus 200 it moves to the left alright so that is vector 3 you can play around with it but when we're changing the position in the script we have to use vector 3 it's at our script that we want to move we want to change the three values of a parks position because that's how it's that's how the game moves parts it used it combines the three values to move it to a certain area now what if you wanted to only change a certain value maybe the x-axis and not the others well it's very simple all you need to do is say vector three vector three dot X for example you say X we know that's not right what you want to do if you're unable to change one value for example the X property you would say game data work space top brick position equals game that work space brick dot position you want to get the current position add the vector three dot new open bracket close bracket so you taken the current position and you're adding on a position vector three position value to it for example let's add fifty onto the x value and nothing else onto the Y or the Z value so the y&z value will be cut the same but the the x value will be will be increased by fifty okay let's just restart the game and expect the brick to move in the x-axis all right just wait for it to load all right it's loaded and the brick has moved fifty studs so that's one two three four five six seven all the way to 50 in the x-axis so that's how you that's that's how you only change one that's how you know change one value X or Y or Z if you wanted to change multiple values you could just change them here but that is how you do vector three and it can get much more advanced if you're doing a vector three maths for example but we won't get there because this is a beginners tutorial that's all you need to know so that is vector three all right now we're gonna move on to our next topic all right the next topic is going to be inserting things into your game so we're gonna look at how to insert parts into the works so to do this we're going to first want to define a variable let's just say part equals and then to actually insert something from a script we just say instance with a capital I instance dot new open bracket close bracket and then inside of these brackets we just type in inside in speech marks we just type in the object you want to insert so I want to insert a part so we're going to say part if you want to know all of the different things you can insert then you just want to want to go to your base plate and you want to go to model and you want to click on advanced objects now this will give you a whole list of things can insert but you want to make sure you get the capitalization correct so for example on part you have to have a capital P all right so we're gonna insert a part and now because we've defined as a variable we can change its properties like we learned in the first part of the video so in if we wanted to make it anchored we could say parts got anchored equals true we could say part brick color equals pretty color dot new and then we could specify a color for example new yellow and we could also give a position let's just say part dot position equals vector 3 dot new opening bracket close bracket 0 0 0 but in fact let's split five studs above the ground once you've specified off properties we can say well we want this part to go we have to give it a parent remember earlier we looked at the parent property we have to tell this script where we want the part to go else it won't be crated so we can just say part drop parent this game got workspace you could just say workspace in lower case but it's best to say game dat workspace with a capital W for workspace alright now let's go and delete this part and let's run the game and see if any new parts are added hopefully they should be I hope they are it works fine it should work alright and we just wait for the game to begin you shouldn't take this long for you it's just because I'm recording a video at the same time and let's have a look there's our pot there's our part which we just created and it's five steps above the ground it's anchored and it is new yellow and it is in the work space so that is how you insert a part into your game very simple and you can do it with lots of other objects you just need to change the properties for example you could insert a GUI into I don't know some well you could insert lots of different objects so that's how you do instancing now let's move on to the next part of this tutorial okay now what we're going to do is we're going to take things up a notch and we're going to go more advanced now we're going to move on to wire loops all right so a while loop is something which repeats lines of code forever okay for example if you wanted to print a message to the output forever or if you wanted to insert a part forever we'll use a a while loop and these are used in game round scripts often for example whenever a game is going it will keep looping infinitely until something happens and we're going to look at that today so to do a while loop you just gotta say while true do and drop a line now when you put true it means it's gonna run infinitely okay because there's no condition a condition is something which is checked every time and if that condition is false then the while loop isn't going to run for example a condition if 2 plus 2 is equal to 4 if it is then it will do whatever is in the while loop but if it's not it will just break out off the loop and it won't keep on repeating forever let's put in a print like we looked at earlier and it will print a message to the output and we can say a while loop passed ok and let's run this now but we can't run it yet because it's going to crash our computer we have to have a wait here so we're gonna say wait and then brackets a number of seconds so I'm going to say not 0.5 seconds because if we didn't have a wait it would keep running infinitely and crash roblox to do let's click on run and open up the output you don't know how to do that just click on view and click on output and you should see a while loop past being printed there you go it says a while loop pass and it will keep printing that okay you can see it's got times 14 or 15 it's pretty hard to see but you can see it says I don't know if we can multiply it but it says times 31 and it will just keep increasing every time every not 0.5 second it's going to keep printing this let's take what we just learned and let's take instancing less instance a new part like we just did here ok and let's see what happens when we put wild Trudy and it will wait not 0.5 and we put this into this part instancing in the middle of it what's going to happen is this this script this inserting of parts is going to keep going forever and ever and infinite parts will be inserted into the game let's have a look at it in action so this parts here but we can't see these parts because they're all being put in the same position but if we look here in the workspace we can see that more parts are being created every noir point 5 seconds it's just repeating the same code over and over over again and it won't stop because the condition we put was true and what a condition is true it will just run forever because there's missing to check but we we will keep taking these parts away but nothing's going to happen they're just going to keep spawning and spawning and spawning so that's a while loop it runs code inside of it forever and it won't stop we have the weight to delay it so it doesn't want in it doesn't run infinitely because if it did we wouldn't notice the change and it would probably crash or a block studio now if you wanted a condition say for example while 2 plus 2 equals 4 would put it here but we have to have 2 equals when we're checking something because if we have 1 equal sign the script will think that we're updating a value but you can't update a value of 4 we cut you can't update a value when you're doing maths so we have to say equals equals now let's try it again everything should work perfectly normal as as before because the condition is true two plus two is equal to four and so it will keep running infinitely because two plus two is never going to be any other number it will always before but let's change the condition to see while two plus two is equal to five do this but two plus two isn't equal to five and it's never going to be equal to five so no part has been created it's just skipped this entire while loop and it's moved on to the next thing when there's nothing else to move on to so what it's done is it's just finished running the script it's just stopped so let's just have a print down here and we can say while loop stops now this isn't going to print when the condition is true because it will just keep infinitely doing this let's head back to the game and run it and we'll just wait for it to load up and when it has there we go we're going to open up the output and there we go nothing has been printed apart from this error we don't need to worry about that because this to do with HTTP service and a plug-in which I've got but you haven't so don't worry about that nothing has been printed but however if we change the while loop to two plus two equals equals of five hold on that should have worked it should have printed a while loop stopped but it did not let's have a look let's have a look at that again maybe I accidentally deleted it maybe I accidentally deleted it there we go while loop stopped that's what it printed because the wallet did not run but if we change two plus two equals four which will make this condition true the wall loop should run infinitely there we go and it does not print while loop stopped because it won't ever stop because it's it's gonna keep instancing parts into the game however there is a way that you can break out of while loops while they're running for example if something's happening during the while loop which which should stop the game then we can break out of this loop we just need to have an if statement now an if statement checks the condition it checks for example two plus two equals four we can check to see if it's three equals four so let's try it again if two plus two equals equals four then we can say else all right okay now this will make no sense to you maybe maybe it will maybe it won't but I'm going to explain it to you anyway so let's get rid of two plus two equals four here and replace it with true so this should run forever so it's gonna run once and then we get to this if statement here and it says is two plus two equal to four or yes it is so it won't do anything but if it isn't equal to four if it's equal to five or something else it's gonna break out of this while loop and it's just going to skip out of this to the next piece of code which is while loop stops now let's change this to five we know that two plus two isn't equal to five so it's gonna run once okay and then it's gonna hit this if statement it's two plus two equal to five well no it's not so it's going to go to this else bit because if the condition isn't true it we can have an else and it will do something else if if the condition isn't true and so in between this else and end we've got a break and this is telling the while loop to just stop repeating stop running infinitely and just break out of this while loop and move to the next piece of code so let's see this in action it should insert one part and then it should just completely quit it should stop inserting any more parts let's have a look let's see if it works so it's inserted one part and then it stopped and then the output we can see it's as a while loop stops this is because there's no condition up here which because it's true and it's always going to run so it's lettuce one for the first time it's weighted nor point five seconds it's inserted the part it's set its parent and then it's hit this if statement and which says it's two plus two equal to five and it isn't so it skipped this part and it goes directly to the else because the else will run when the condition is false and two plus two isn't equal to 4/5 so it's false so it's being told to break and so when we have break in a while loop it means to stop running the code inside of the while loop and just to move on to the next to the next piece of code outside of it and so it printed while loop stops and so that's how you break out of a while loop which supposedly can run infinitely you don't have to have a break if you don't want the while routes end but usually all while loops will come to an end at some point in the game so that is the end of the while loop section I have videos on every single topic which we just covered some of which are over 30 minutes long so you can understand something here then you can always refer back to the playlist which is on the right side of your screen now just click on it and you can start watching the videos I hope you enjoyed this if you did then please make sure to leave a like and click on this big subscribe button the album blocks logo in the middle of your screen now to subscribe to my channel and don't forget to turn on the notification bow so that you get notified whenever I post a new video so you don't miss out on anything this is Alvin blocks telling you to keep scripting