How To Script On Roblox 2021 - Episode 1 (Properties)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this series is going to teach you how to script on roblox and in the first video i thought we'd look at something called properties so any roblox object has a list of properties which describes how it acts in the game how it looks for example and if you go to the view tab and click properties then whenever you select something such as a part you're going to see these lists of properties so we've got properties which change the color of a part we've got properties that change is transparency we've got material properties loads of different properties which change how this part looks and acts now these properties are very important in scripting because you can change them with a script and that's what scripting really is it's just about changing properties at different times and then when you put together all of these changing properties you you start to make your game interactive and so let me show you how you can change these properties with a script it's very simple so if we go into the server script service this is where we're going to put our scripts for this video we're going to insert a script okay this is a server script we'll dive into the different types of scripts in another video but what you need to know i'm just going to make my script a little bit bigger what you need to know is that to firstly change a property you need to tell the script which object you want to change the properties of so in this case we want to change this parts property so let's say we want to change its transparency which basically tells us whether you can see through a part or not now we can obviously change this in the properties window but what if we wanted to change it while the game is running through a script well we can't just you know click it and change it because we aren't controlling the game we have to do it through a script so we have to tell the script which object we want to change a property of and to do that we reference it and referencing is just telling the script where the object is in the game so this part is inside of the workspace the workspace is a service and it contains all of the parts and objects that we can see in the game such as this part this terrain etc so to reference this part very simple we just have to say game because the workspace service is in the game what we're looking at in the explorer is everything inside the game so firstly when we want to reference a service we have to say game so we say game and then from there we can choose one of these services now we're choosing the workspace and then we can choose any object that's inside this workspace because you can see these three objects the camera terrain and parts are all inside of the workspace when we close the workspace service you can see they get hidden and you can see that they're indented slightly which shows that they're members of the workspace so anything you can see in the game world that you can interact with and select such as this part is in the workspace so we say game.workspace and then dot each time when you want to reference a new object inside of the previous one so we want to look inside the workspace and we want to get this part so let's write out part that's the name of it there you go and it showed up in the autocomplete menu we now have our part so now that we've got our part referenced we've got access to the part we can now uh view all of these properties if we click on dot so if we press dot to insert a dot you can see all of these blue icon things appear in this list right don't worry about these ones we'll get to them in a later video so all of these blue icon things are called properties things that we can change so for example let's choose one of them we can view all of the properties available in this properties window so let's choose one so let's choose uh transparency okay so once we've now got our property we can change it just by saying equals and then we can set it to a new number obviously transparency is a number it's between zero and one zero being opaque you can't see through it and one being totally transparent you can see through it so it's a number between zero and one so any number in between will show a degree of transparency okay so if we just set this to one then it's going to become transparent fully transparent we'll be able to see through it so we have just updated the transparency property of this part to be one now this isn't going to run until we start the game because all server scripts like this one here only start running when the game starts running now this game is currently not running but to run it we can click on this little arrow under the play button and click on run we can press f8 and if you look at that the part has disappeared it's still in the game but it's transparency property has just been set to one so that's because these scripts ran as soon as the game began and instantly set the parts transparency to zero but we've just manually gone and changed it back to zero through the properties tab so that is a property there are loads of properties in roblox studio there are so many actually that we don't just change transfer change properties by setting the property to a new number for example if we look at our name property this describes the name of the part so i could change this to be called brick or i could call it alvin blocks you can call it whatever you want but it has to be text right it has to be letters and characters you can also have numbers but in scripting we whenever we want to set the text of something uh such as name we use something called a string so let's just set the name property to be equal to something we still use the equal sign that just tells the script that we're updating the property to a new value but this time we want to set it to some text so if we wanted to call it my part for example well this wouldn't work we can't just say my part because the script gets confused here it's thinking well i i don't know what you mean by my part it's unknown to me i can't see it in the game anywhere it probably thinks we're looking for an object called my part but to get around this we just put it in a speech marks like this in in these like quotes so you can use speech marks or you can use the these quotes or apostrophes now you can see it's gone pink and that's because we have just defined a string and a string is a it is any characters of text you can have numbers as well but to be a string it's within these speech marks and that just tells the script that we are inserting some text here and that it shouldn't get confused this is just some text that we want to set our property to so this is a string because it is some text some characters some letters numbers wrapped inside these speech marks so whenever you're setting a name or using some text as a property you're going to use those speech marks because it's a string let's just look at some other properties for example material now if you wanted to update the material what we would do is instead of saying let's see what materials have we got we've got grass for example instead of saying grass all right you could say it in speech marks like this right but for materials it's best practice to use something called an enum an enumeration like this so you say enum and then you do a dot and then you do the name of the property so material and then another dot and the game will actually so the scripts will actually give you a list of materials to choose from and this is what an enum does it gives you a selectable list and this is just best practice whenever you're setting something such as a material which is a drop down so if you were to select pebble this would be your property so you're you're getting it from a list and that's what an enum is it is a little bit confusing you may be wondering you know why can't you just put it in speech marks but it's best practice to put it as an enum and an enum is just it's just a list it lets you choose from a predefined list and that is just best practice for roblox scripting if you run this script you can see immediately hold on we have an error let's go to the output window and it says part is not a valid member of workspace all right so we're learning something already here we've got an error now you're going to encounter a lot of errors in your code and that's because sometimes you will have made a typo or you will have forgotten to change something and whenever your script doesn't work now we could tell it didn't work because the material didn't update it's still marvel what we want it to be cobblestone so what's gone wrong well if we go to the output window by clicking view output then the script will print out an error message and it says server script so in this server script one line one here you can see line one part is not a valid member of workspace so it's saying i looked in the workspace for a a brick called part and it's not there that's because we changed the name to alvin blocks so let's change that to alvin blocks and run the game and this time it should instantly update our parts property to cobblestone don't worry about these errors here that's from a plug-in that i've got that is malfunctioning at the moment but there you go that is how you uh change properties in roblox scripting very important and also you've learned that there are different data types that we can set properties to so not just numbers but also strings whenever we want text we wrap them in those speech marks materials we use enums and also for properties such as anchored archivable can collide for example can collide is a property which we'll learn about in the future you can also set them to be boolean values and a boolean value is true or false and that represents whether one of these boxes would be checked or unchecked so false would be unchecked true would be checked we'll be looking at those properties in another video but thanks for watching your first roblox scripting tutorial if you enjoyed it please drop a like drop me a comment with any future videos you want to learn about and don't forget to subscribe and turn on your notifications of course thanks for watching i'll see you in the next one
Info
Channel: AlvinBlox
Views: 353,915
Rating: undefined out of 5
Keywords: roblox, alvinblox, roblox scripting, how to script on roblox, roblox scripting tutorials, roblox how to code, roblox lua, roblox how to script 2021, roblox beginners scripting tutorials
Id: aX0Kw_txrIY
Channel Id: undefined
Length: 10min 47sec (647 seconds)
Published: Fri Mar 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.