Hello my friends, how are you? this is Wo Starting here with another video and welcome to the first episode of our new script guide series and in this series I will try to teach you how you can learn to program on Roblox itself and yes, I will prove to you that this is a very possible thing, but before I start explaining the content of this video, I would like to make a recommendation for those people who are new here at Roblox Studio, in case you are new here at Roblox and Even if you have never opened Roblox Studio, I will recommend you my Roblox Studio basic guide video. In this video of mine, you will learn some basic things, in this case you will receive instructions on how you can open Roblox Studio and also some tips about its interface so that you can at least have some basis to continue our series here, right, because the objective of this series is to teach you how to program and in today's video I'm going to talk about programming logic and variables before starting to explanation itself about programming logic, it is important to remember a little how machines work, right, making a nice summary here, machines basically only work with the instructions that human beings, in this case, programmers give them and they go there and follow them exactly what the programmer asked them to do is just that, like machines only do what they are told, at least as far as I know, right.
In other words, the machine will only be able to do something if you know how to do that thing, only the difference between a machine and a human being I imagine you know that it is the issue of speed and precision, machines can also do a multitude of calculations very quickly which are instantaneous and things that human beings could take a long time to do, for example human beings They can program a cell phone manually, let's say, without electricity, like, they can make it with a lot of effort or even move it, let's say, but it's a totally unfeasible thing, it doesn't make any sense to do that because it would have to sell to many people, in this case, billions of people per example to be more exact But back to the point, the machines work very quickly and also precisely, right? In other words, they try to do exactly what you told them to do, but it's a problem, let's say, that's what they only do, like they only follow instructions, what it means that they don't have any type of prior knowledge, for example, we human beings throughout our lives, our human development, we learn to walk, we learn to talk, we learn to do a lot of things, right, it's already a machine, it's not a machine, it doesn't understand these our concepts here, she will only understand our concepts if we explain to her what it means and it is precisely in this part that programming logic comes in, when you think about how to educate machines, let's say, or in the case here of Roblox the scripts the machines it only has access to a very unlimited number of tools, which means that for example for you to make the NPC and walk around in Roblox Studio The machine cannot do this with the primitive tools it has, however with these resources it In this case, with these capabilities it has, it can do that If you give it a series of instructions, for example, let's say there is a drawing machine that it makes drawings there following lines, for example a single line, I don't think it is capable of doing it no geometric shape in this one, if I'm not mistaken, but if I give some instructions for this machine, for example something like Look, just take the line you know how to make and make three lines so that between them there was this angle here and that's it, we we have a triangle and in programming as a whole this is more or less how it works and of course in Roblox also for example if I want to change the position of a part I can simply take the part here and I will create it here now using part here with the right button, right, if you want to change its position I can get the move tool here and change it here or I can also go here to the part properties and change the position directly here When we program a script, it doesn't have access to this tool that we have here in Roblox Studio, so the only chance for it to move something is just properties, but now we have a problem, I wanted the script to do this in a smooth way, right? that when I'm going to have something here, for example, I'm going to move the part here on the Y axis.
I'm going to put a 20 here, for example, notice that it teleports part and that's not what I wanted, it changed the right position in the part, beauty, I just wanted it he would do this in a smoother way, right, but now that the problem is the script, he doesn't know what it means to move smoothly, but look what we can do, we can interpret and move smoothly as a smooth change of the position property which in this case would be the property that talks about the position of the object, notice that when they change it smoothly there that thing that is inside the crame it changes in a smooth way, that is, I need to specify a code for the machine that makes this part be kind of which teleports a little bit each time the code is executed, so for example once it will teleport here, then here, then here, and following this loop here several times, repeating this process, it will move smoothly, it will cause this illusion that, in fact, It's not quite what we would have wanted in the beginning but it's like it's an illusion and let's see that part smoothly so realize that for you to program anything you're going to have to think about that thing and interpret how you can make a script understand that what do you want in other words you would have to translate your idea into scripts so that anyone can do it even a machine for example to make a person do it for you you can use this example here you can tell the person something like Look, just take this part and move it smoothly to point one hundredth 1% of the way and you will repeat this process 100 times until you get to the point I want when you write the code, that's more or less what you'll have to do Of course, it's just an example here, right, a very improvised example here at the moment, but that's basically it, programming logic is actually a skill that you develop over time, so it's only practice that will ensure that you have good knowledge about the logic of programming. So you will be able to realize that the logic of programming will be present all the programming videos So I would like to ask you to be calm about this because learning to program is something that apparently is a bit complicated But you will realize over time that it is not because This is essential that you have a lot of patience and that you try to get used to it over time and programming logic is basically that now I'm going to teach you the variables and first we have to create a script, right, so that we can edit it and that I can teach you in practice. So I'm going to create a script here in ServerScriptService, right click here and create a script and when you've created a script it will automatically open with this message here print hello Word For now I'm not going to explain what this means here because it's something that's a little beyond what we are now.
In short, variables are elements that hold a reference to some object or value that will be used in the script and, as the script itself says, name and this reference can change that's why in my variable There are two ways you can create a variable in a more basic way is by creating the global variable that I'm not going to explain that much now, so you can simply put the name of the variable, for example object (Oops, I turned on capslock here). . .
object is the same as something, in this case I'm going to give the name in this part here I'm going to get it this part that I had created here in the workspace, right, I'm going to pull it here I'm going to put it here so Part is equal to Workspace. Part why did I do this? Part is the name of my variable, the same is to define the value of the variable and Workspace.
Part is the reference of that object. Note that it is inside the Workspace, so in the In this case, this word means this Workspace service and then I used the dot to access the member that is inside the Workspace, which in this case I remember that I wanted to access is a part member, so you will always use this dot to get the reference of a object that is inside the other or it can also be a property in this case I used it as an object but it can also be a property for example if you want to get the color of this object you could put it here point is BrickColor for example since it would not be an object it would be the property of that part object or you can also use square brackets which will work in the same way I can put it like this Part and here I can put it (Oops I put something here, nothing to do with it) I can put Brick color this one here will be the same something that I had mentioned previously, the difference that may look prettier in some cases. So if you prefer, you can use it like this but I recommend not using it on everything because otherwise it looks a little strange, but this way I showed you here and it is not widely used, it is not very cool to use, in this case it would be the creation of a Global variable, as I told you, I will not explain it today.
What local variable and global variable mean is something that I will explain throughout this series. but the difference in the construction of the variable is that the Global is written this way, which would be the same name and the Workspace. Part, which in this case would be a reference to the object or the value that it will store, and the local variable would be like this, you just put it in front and the rest remains the same, the difference is that you are going to put this location here at the front, they generally use the location because it is more conventional, it is more "cute", let's say, of course the difference is not only in the beauty of the aesthetics, but it is one that in the the beginning will be most of the time it will be more about aesthetics even by default I recommend you always work with local variable beauty this part here of Global I recommend that you don't think too much about it for now at least in other words I'm explaining it to the script which part in this case whenever I talk about parts in the Script I am referring to this object here and variable is one of the things that you will use most in the Script generally most scripts start with a variable or with a bunch of variable, right, because it has a complex script that includes many variables at the beginning.
It is also used to get services, so for example, to create a variable here with ReplicatedStorage, I put it. Generally, I at least put the full name, right, I put ReplicatedStorage. But some people prefer to just put RS.
or something like that Anyway, I can put whatever name I want, okay? ReplicatedStorage is the same as game:GetService("ReplicatedStorage") I'm not going to explain yet why I used a colon and what this GetService() means because as I told you I'm going to take one step at a time Don't worry too much about it That's fine for now, but in case you're curious, this is how you get a service by scripting the functions or, in this case, functions, this is content that I'll cover in the next class, but I'm going to give a little spoiler, so to speak, because I'm going to have to work with you on print function that Let's say that the most essential function of scripts, that is, this function doesn't do anything special but it can help you a lot I don't know if you have this window open but I'm going to open it for you now here I go take the display tab here and I'll look for the output here, if I'm not mistaken, this one here, this icon here will open the output, this output is what. It will display some little things here for us in relation to the script or even the game If it's on Roblox it's sending a message, plugins can also be placed here, for example, this role that Explorer, in other words, is like a kind of console.
But you can also inject it, so to speak, it's a script directly using the command bar just click with the right button up here and get the command bar here and copy and paste some scripts here, I'm not going to do that because the command bar is a little thing that's kind of complicated to show in a video, right? It's very small and it's at the bottom, it's the print function, it's used to show some message here in the output, so for example, if I put it here, it's or put it between these quotation marks here, which is what the text means, and then I 'll explain it to you here. I'm going to put the message Hello So now I'm going to test my game here by clicking on the play button here, notice that I tested my game here I just opened my test site here and notice that the message Hello already appeared there at the beginning, you can even give it zoom you can click the CTRL hold the left CTRL in this case and place it here with the mouse wheel, right You can scroll with the wheel on the mouse and you will be able to zoom here in this output maybe you are wondering But why is it I would use something that is to show in the output, since this will not do anything in my game, so my main part of this function is that this function is actually very useful for showing what is happening in your script.
some elements that will block the execution of the code for some reason, either due to some condition or simply due to an error, so if you are making a very complex shape, it is interesting to have some way of being able to monitor what is happening, right? an execution line I'm going to put another print here for you to see here, now I'm going to put the word world, I'm going to put it to execute also a tip that I give you here is that I recommend that you press F8 which would be the button to execute why? because in this case it will run directly on the server it will only open the server and will not open a player and as it will not have to load my player it will load much faster you do this when you test script and not local script which is another little thing that I'm also not going to talk about much here in this video, but in this case it's very useful, so I'm going to click on the execute button here and let's test the code here, right, and notice that it first printed the scroll and then the world that Remembering that this here happens in an order, there is even the date that happened in this case, the time, right?
also notice that the moment that happened because here we have hours, minutes, seconds and milliseconds, look at the difference here, you can't even notice it, in fact, even according to it, let's say like this This is to give you an idea of how fast a script runs in Roblox. So when you work with optimization, which is something that you will see a lot in the future and you will see that every millisecond matters, but in the end, what matters for now is you know that the script always executes in an order that is from top to bottom, there are some exceptions, some things that block this rule, let's say, but as I told you, I'm going to change one pass at a time, I'm not going to say much for now, What you really need to learn in this video is how you create variables and what you are going to use them for, which in this case is what I'm going to do here now with you, okay, we have our variables here but what can I do with them Look at this here it is interesting I can create a variable called message I can put it here is the same or there world instead until I type this this this message here again inside the print for example I can simply put message and then it will get the value In this case, the reference to the word message of the message variable is what I told you at the beginning, which would be what I'm going to create through a script. In this case, I'm going to speak through a script here.
" is a string a message called "Hello world" so every time I say message in the Script it means hello world so this is the code I have here to show you and notice that it changed here now it added "Hello world" there It printed exactly as I told you, it is interesting to create variables also for you to make some configurations so for example you can put there a cooldown for some ability to happen you can write this type of configuration at the beginning of the script but basically speaking you will use variables to get services and objects you can just see it in any video In this case, I'm going to be doing some script that will have an object there that I'm going to be getting with a variable or a series of objects, right, an interface is formed, for example, and if you just watch this class, you'll think that variables aren't used for a lot but you will realize over time that yes they are extremely useful and that you will understand in the future that creating a variable is a more complicated task than it seems and yes we will definitely use variables in the next videos in this series so you need to learning what is variable in order to continue with our beauty course will be confusing for now, but I guarantee you that you will understand what is variable as the videos go by.