Roblox is a gaming platform that allows anyone to create their own games with Roblox Studio and share them with the world. Have you ever wondered how to teach yourself scripting on Roblox? Whether you have an interest in designing video games for fun, or hope to make a career out of game design someday, learning Roblox scripting is a fun and rewarding way to get started! Show
Learn how to teach yourself scripting on RobloxThere are a wide variety of options available for anyone to learn how to create and use scripting in Roblox. These are just a few examples of some of the easiest methods. 1. Roblox YouTube videosThere are hundreds of tutorial videos available to learn Roblox scripting on YouTube. Many developers have created a series of videos starting from how to open Roblox Studio all the way through to advanced scripting techniques. There are plenty of good videos available that will show up in search results, such as this Roblox video (see screen capture below). The benefit of learning through YouTube videos is that the information can be watched, paused, and rewatched indefinitely until the examples make sense. However, the challenging part of this method is that it is usually difficult to ask questions about the video content or coding. The channel host may or may not respond to questions in the comment section, or may not display a way to be reached directly in the video description for questions. 2. Free Tutorial ArticlesRoblox Studio developers provide a website of useful tutorial articles available to anyone who wants to learn Lua scripting. Their website is a free resource that teaches scripting with written code examples and images. Each web page steps the learner through various skills, from beginner to expert, and is great for fluent readers and those who are self-motivated. See an example page here. The tutorial is easy to follow and has great visual examples. However, like the YouTube videos, if the reader has questions about the content, it may be hard to get an answer or know where and who to ask when questions arise. There are also great Roblox coding books, if you prefer reading to learn new skills. And Roblox tutorial articles. 3. Free Live Online ClassesThe fastest and easiest way to learn scripting is with live online classes. Check out our free introductory Roblox Studio scripting course that can set you off on a fast path to learning and understanding Lua, the scripting language used in Roblox Studio. Classes include visual examples, written code examples, and live instruction to guide learners through the process and answer questions, leading to a higher quality of scripting ability than either written tutorials or videos alone can provide. Perhaps the best part of taking an online tutorial class is that you can ask questions in the moment, and certified teachers can guide learners individually within a small group that works together to create something fun! 4. Decompile and Modify Free ModelsThe Roblox website and Roblox Studio contain free scripts that can be downloaded and placed directly into the game design interface. These pre-built scripts are great for people just starting out trying to make game items perform specific tasks in the game, and can be modified and decompiled as a way to learn how to build similar scripts. However, these kinds of free scripts should be added with caution. Scripts can be designed and shared by anyone, and may contain viruses that can infect both your game and your computer. Be sure to use free model scripts that come directly from Roblox instead of searching for developer-made options. 5. Reading Roblox Developer Forum PostsDeveloper forum posts usually contain scripting questions posted out to the general public asking for specific ways to code script to solve a particular problem. Reading through forum posts is a great way to spark scripting ideas and also learn how to create code that might work for general purposes. For those who learn by examples, this is a handy method to gain an understanding of Roblox scripting, but might be a better resource for once a basic understanding of Lua scripting has been obtained. Teach yourself scripting on RobloxNo matter which method feels like it makes the most sense, learning to code and create script in Roblox Studio to enhance your game design is a very fun and rewarding experience. Since many coding languages are similar, learning Roblox scripting is a great introduction into learning to read and write code for many gaming platforms. Up next, learn about Roblox coding basics. For an easy and fun introduction to scripting Lua and creating Roblox games, join our free Roblox class. Then, complete our Roblox learning program with Roblox camps - all designed by professionals from Google, Stanford, and MIT, and led live by an expert. Written by Kari Tonkin, a Create & Learn instructor. Kari has been teaching a wide variety of courses and ages for more than twenty-six years. Some of her favorite subjects to teach include computer science, graphic design, mathematics, and coding languages. She received a Master’s Degree in Curriculum Design with Technology Integration from Black Hills State University in 2016 and has used this knowledge to stay current on new technology trends in education. When she is not working, Kari enjoys playing video games with her family, including Roblox and Minecraft, hiking and camping, and traveling around the United States.
Welcome! If you're new to scripting, you've come to the right place. This is a complete beginner tutorial series that will teach you the fundamentals of Roblox scripting. I know you want to start clicking on things and learning things, I want to take a minute to explain what you will and won't learn. Author's Notes
Inserting a PartOpen Roblox Studio for the first time and create a Baseplate in the "New" tab, and you'll see this big area. If you don't see anything but that baseplate, don't worry, you don't have to put anything in there for now. 50% of your time is spent in the viewport. If you're modeling or moving something around, you'll do it here. Let's talk about that more. If you go down into your Explorer panel on the side, you'll see a "Workspace" tab. This tab holds all Parts in the game. If you do not see an Explorer Window, go to the View Tab, then turn on the Explorer window. You'll also need the Properties window. Go back to the Home window and click Part (the button with the cube on it.) A gray brick should appear on the baseplate. To move it around, you can use the "Select" tool or the "Move" tool. You can move around the part along one dimension by pulling on one of the arrows using the Move tool. You can also resize the part using the "Scale" Tool and rotate it using the "Rotate" tool. Now you need to know how to insert other parts into your game, like fire. Go to the Explorer window and then find the Workspace tab. Open the arrow beside it and find the Part. Then, hover over the Part tab, click the plus sign, and insert a "Fire" object. If you cannot find it, you can use the search bar. Congratulations, you just created your first fire part! But what about scripting? We'll get to that right now... PropertiesIn the Newbie's Scripting Guide, you learned a had a very broad understanding of a property, which we'll explain in more detail now. A property is a value attributed to a part that makes it look like what it is. For example, the Transparency, Size, and Position are all properties of a part. Property values are the numbers or words that are used to set a property. How do you do that? You can go to the Properties window, find the property, then type in the value. The main properties a beginner should know are:
But how do you set a property using a script? Well... Making PathsYou should have already have a basic idea on how to make a path if you have read the Newbie's guide, but if you haven't, this section will explain it briefly. Create a part and a script into the Workspace. Delete any existing code in the script.
First we need to access the part. Start by typing "game". The word "game" should turn blue (or red if you had dark mode enabled.) Now, access the Workspace, by typing a period, then "Workspace". Then, access the Part. You'll notice that the part tab has a little indent compared to the Workspace tab. We say that the Part is the Workspace's "child," and that the Workspace is the Part's "parent." In Roblox, the Explorer window is organised sort of like a hierarchy, where objects are placed on a sort of "rank." Of course, if you had renamed the Part, you'd need to replace "Part" with the name you gave it. Also, make sure that no two parts are given the same name: otherwise the script won't know which part to access. Now we set the property. We say that the property is a child of the part. So... game.Workspace.Part.Transparency To set the value, type an equal sign, followed by the value. So the completed code would be... game.Workspace.Part.Transparency = 1 Spaces around the equal sign is optional, but it makes the script neater. So, when you playtest the game, you'll see that the part suddenly vanishes. In reality, it had just been made invisible by the script. Alternatively, in the Explorer window, drag the script onto the part, if it is done correctly, it should look like this:
script.Parent.Transparency = 1 There are a few new terms here. When you say "script," the game will assume it means the script the text is on. When you say Parent, instead of looking for the script's child, it'll access its parent. If you had made a mistake, chances are the game will have noticed it. Go to the View Tab, then click on "Output." A window will appear, and if the game found an error, it would print an error message nice and bold in red. Clicking on the red message will take you to the source of the problem. Note: If you need to set a text value, place the value in quotations. Also, Color3 and BrickColor values are done differently, and I'll need to cover that later. An alternative way to access a child is by wrapping the name in quotations and square brackets. game.Workspace["Killbrick"] game.Workspace.Killbrick Both of the above lines serve the same function. However, you must use the square brackets method if the name of the object contains spaces. (For example, if "Killbrick" was renamed to "Kill brick," you would use the square brackets method. Now, things will get a tad bit more complex. A "folder" is an object that can be inserted into the Workspace that holds multiple objects together as a sort of organizational tool. A "model" is another object that serves a similar function. Oftentimes developers will place models inside folders. A good rule is to start with "game," then work your way down to the object.
game.Workspace.Folder.Model.Part.Transparency = 0 You can see that this shows a more complicated hierarchy. The part is placed in a model, inside a folder, in the Workspace. Of course in these complicated situations, names such as "Folder," "Model," and "Part" should be renamed to prevent confusion. A good rule of thumb is that if something should be accessed in a script, it should ALWAYS be renamed. Printing is an essential part of debugging your game. By default, the following code should already be in your script when you create one: Now, go to the View tab on the top of the screen and click "Output." A window should appear. If you play your game, you will see that "Hello world!" was posted in the Output window. It has no function in a live server, but is essential should you come across a bug you can't solve. VariablesNow we discuss variables. Variables are, in short, placeholders for data. It would store information such as numbers and text. Then, in future use, instead of typing in those values, one can just mention the variable. Think of them like a colloquialism in the English language (for example "kinda," "dunno," or "ok"). These words are simply a way to informally shorten a sentence. When we first mention a variable we are declaring it. This is how we do it: Here, we are declaring a variable named "Var". We are also establishing that the variable var is equal to 0. The local is optional, but it is common practice to use it always because it is faster for the system to obtain. Note: This is case sensitive. Therefore, "var" and "Var" are two completely different variables. There are 5 main types of variable values: InstancesAll these are instances. An instance is an object in the Explorer. This refers to parts, light objects, and more. An example of this is the Parent property of a part. To set an instance variable, make a path, as explained above: local Car = game.Workspace.Car Integer ValuesAn int value, otherwise known as an integer, is basically any number that is not a decimal. An example of this is the Brightness setting of a light object. To set an int value, you can simply enter the number. Note that the number should turn aqua (or yellow for dark mode). FloatA double-precision floating point format, often shortened to float, is any number that allows for decimals. Usually, they never have more than 3 decimal places. Just like int values, you can simply enter the value. BooleanA boolean, otherwise known as a bool value, is a value that is either true or false (yes or no). In the Properties window, the properties with a checkbox is a boolean. Checkboxes imply booleans. To set a boolean, enter either true or false. StringsA string is any text that uses letters, symbols or spaces. To enter one, you must wrap it in quotation marks. local StringVar = "Cheese" Here, the word "Cheese" is wrapped in quotations. Of course, there are other data types, like CFrame and Enum, but we'll get to those later. NilNil, also known as null in other languages, is nothing; the absence of any data. Nil is not a data type in its own right, therefore variables of any data type can be set to nil. When referring to Instances, nil refers to an object that does not exist. Accessing VariablesNow, we need to know how to use the variables. If you want to do something with a variable, just substitute the value with the variable name. What I mean is that both of these scripts yield the same results. --Script 1 game.Workspace.Car.CanCollide = true --Script 2 local Car = game.Workspace.Car Car.CanCollide = true You can see that variables are direct substitutions. Note that if you are accessing or updating a variable, do not use local. Only use local the first time the variable is mentioned. However, this lengthens the script, and makes it more complicated. In this case, the first script would be more convenient than the second. However, variables are mostly used when a value is mentioned more than once. But what's the difference between these two lines? print(VariableName) print("VariableName") When you put data in strings, you need to place them in quotation marks. So, in the second line, you are telling the script to print the string, so you would see "VariableName" in the output window. In the first line, you are telling the script to print the variable, so it would print the value. However, make sure the variable name is spelled correctly, otherwise it'll get an error. Now what is wrong with this script? Car.Transparency = 1 local Car = game.Workspace.Car Remember, Roblox Lua uses the same writing system as English; it is read left to right, top to bottom. Therefore, the script won't know what "car" is until it reaches line 2. Line 1 will break. Note that variables cannot be accessed from other scripts. The .new() ConstructorEarlier, I left you hanging on how to set color values. BrickColor allows you to use a color from a preset list of colors that can be found here. script.Parent.BrickColor = BrickColor.new("Really red") The above script changes the BrickColor to "Really red," one of the colors in the list. We call this a .new constructor. Basically, for certain data types, including BrickColor, we need to use a .new constructor to create a value for the data. Generally, it would work like this: Color, however, is done differently, as it uses Color3. This is a data type that uses numbers, not names. There are 3 constructors for this data type, and see this tutorial if you wish to see an explanation for this constructor. script.Parent.Color = Color3.new(0,1,0) script.Parent.Color = Color3.fromRGB(230,230,230) script.Parent.Color = Color3.fromHSV(0,1,0) Vector3There's another exception to setting properties. You will notice that the Roblox place is three-dimensional. It has three values: X, Y, and Z, each for one of the dimensions. Position and Size both use three values: X, Y, and Z. To set these, we use Vector3. script.Parent.Position = Vector3.new(1,2,3) Here, I am setting the X coordinate to 1, the Y coordinate to 2, and the Z coordinate to 3. Again, we use the .new constructor. To learn to set Orientation, read here. Now, what if we don't want to forget what each line does? It'd be such a hassle to have to read each line over and over again. So, placing 2 dashes, followed by the text, will make the script ignore the text. script.Parent.Transparency = 1 --Makes brick invisible. In this case, the script will perform the code, before ignoring the text you wrote after. FunctionsWhich brings us to the final topic of the beginner tutorial: functions! A function, like a variable, is another way to simplify code. Think of it like leaving your wallet in your pocket instead of your bag to make it easier to get. A function is a piece of code that can be used over and over again. Like variables, we declare them. We do it like this: local function Name() --Code end A few notes here:
That is a lot of points, but it will become second nature when you practice using them more often. To make it actually work, though, we call the function. We do it just like this: And that's all you need to know for now! Go over to the intermediate tutorial to continue. Good day. |