Roblox Lua for Beginners - Learn Lua in 20 Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to show you the ins and outs of Roblox studio and Roblox scripting what if I told you you could craft an entire world from the comfort of your living room what if you had the power to design build and operate your very own Universe pixel by pixel line of Code by line of code that's what scripty can do for you and let me tell you it's not just about games it's about Mastery it's about creation it's about living a life less ordinary now you might be thinking I'm not a programmer I can't code I've been there trust me I was once in your shoes thinking is this really for me the answer is yes yes it is because if I can learn it so can you why learn scripting you ask let me give you a few reasons is a doorway to a whole new world of possibilities with scripting you can bring your imagination to life create anything you desire games apps websites you name it but it's not just about that it's about having a Competitive Edge in this digital age every industry every job is getting more technical more digital scripting is a language of the future it's a skill that opens doors and sets you apart but you know what the best part is it's accessible it's not something reserved for the elite or those with a fancy degree or those working in Silicon Valley it's for you it's for everyone so come on this journey with me together we will explore the fascinating world of scripting we will make mistakes we will learn and most importantly we will grow because in this world of scripting the only limit is your imagination so let's dive in this is where your Journey Begins this is why you need scripting now let's open Roblox studio and create a base plate let's start with the basics variables they're Simply Storage locations let's say we have a variable called my name look how we declare it let's create a script let's say local my name equals John this is how you do to Define your first variable in Roblox Studio the local keyword defines the scope which we'll talk about later the value John is now stored in the variable my name next let's talk about instances and properties in Roblox everything you see in the game is an instance of an object class let's say we want to change the brick color of a block named my block here's how we do it local block equals workspace find first child my block and if we had a block in our workspace called my blocks let's just rename the base plate to my block this would work properly then we want to change the brick color as an example so let's do brick block dot brick color equals brick color dot new bright red okay we first find the block then we change its brick color property strings are sequences sequences of characters enclosed in a single or double quotes for example we could do local my string equals hello world we can also use concatenation by using dot dot so I could do local greeting equals hello space got a comma here then we can do local name equals John okay then to print with coconut Nation we can do print greeting dot name dot dot name and this is going to print the output hello John nil is a special type representing no value or No Object it's not the same as zero false or any MP string for example Apple we could do local myvar equals nil this means that mayavar doesn't hold any value booleans are true or false values for example local is reigning equals false it tells us whether it's raining or not booleans are often used in conditions next the weight function the weight function is used to pause the script for a specified amount of time here's how it works we do print test wait to print it is finished after two seconds here it is will be printed numbers in Lua the language used in Roblox scripting don't have commas we can write a thousand as a thousand not a thousand with a comma look at this local large number equals step number here then we can print large numbers so they don't require commas the test.weight function is similar to weight but it allows for a more precise waiting time so if we do print task weight is loading then we give you task dot weight 1.5 then we do print here it is okay just like wait after 1.5 seconds here it is will be printed let's print something on the output window we run this script so let's say print hello world okay it's going to print the output hello world will appear in the output window this is great for debugging and seeing what's happening in your script with scripting we can do math operations look at this example local sum equals five plus three let me do print sum okay and this will output eight okay we can do all basic operations addition subtraction multiplication and division so we would for division we could use a slash like this and for multiplication we can do an asterisk symbol by doing this and then we can also do a minus so that would be two okay excited about what we learned so far well hold on to your seats we're about to take it to the next level get ready functions are blocks of code designed to perform a particular task here's a simple function local function say hello print hello world okay when this function is called it prints hello world functions can also take parameters let's look at this example if we put our name game in here and we add some concatenation here so here we go dot dot now we added comma here hello world and then we can change this world to name as a parameter if we call greet if we call the Greet we call the say hello function so let's do say hello and we put our name in here so it's John it will print hello John that's how you use parameters functions can also return values here's a function that adds two numbers local function add numbers now we could do number one and number two then we can return number one plus number two okay if we if we call the add numbers function and we do five and three it will return eight because it's adding them comments are lines of code ignored by the computer that they're for you to others to read in little we can use slash slash for single line comments so this is a comment okay for a multi-line comment we can use slash slash bracket bracket and then we can put all of our comment inside of here so this is a multi line comment okay the keyword local just defines the scope of a variable or function local means it can only be accessed within the block of code where it is declared without local it's Global and cons it's Global can be accessed anywhere in the script so a local variable is local Global local local VAR equals and this is a local so I am local now we're going to go over global variables which are Global without the local this is going to be called I am Global okay localvar is the only available within its block while Global VAR is can be accessible anywhere in the script we can we call a function to execute its code let's call our greet function greet we could say any names like Sarah for example that's going to say hello to Sarah if statements are used for decision making here's an example you can do local num equals five then we can do if num is greater than three then print the number is greater than three since five is greater than three the number is greater than three will be printed in luo we can use double equals to check if two values are equal to each other single equals is used for assignment let's see this in action local num equals five if num is equal equal to five then we'll print the number is five okay since num is indeed five the number is five will be printed color three values represent colors let's say we want to change our blocks color to Red we would write block dot brick color equals brick color dot new then we can do color color three dot dot from RGB 255.00 this is going to make it red 255 for red zero for green and zero for blue gives us bright red we can also use else to specify what happens if recognition is not met let's look at an example local weather equals Sunny if weather is equal equal to rainy then rainy then we will print bring an umbrella else we will print no need for an umbrella since the weather is not Randy it prints no need for an umbrella we could use elsif to specify a new condition If the previous condition was not met let's expand our weather example so if we wanted to add an else if statement we could do else if weather is equal equal to cloudy then we can we can say print maybe bring an umbrella okay here since the weather is cloudy it's still it prints maybe bring an umbrella okay but if it was equal to Sunny it would equal this so it's it's not equal to anything currently these options are not currently selected events are how scripts respond to user interactions or changes in the game let's say we want to print a message when the part is touched we could do local part equals workspace colon find first child my block okay then we can do local function on touch uh parentheses then we can do print part has been touched okay then we're going to say the event so let's do part dot touched connect on touch this is a colon right here okay so after we do that we could come down here and when my part is touched part has been touched will be printed into the console fine first child is used to find a child of an instance let's find a part named my part which is used up here if my part exists in the workspace it'll be assigned to the variable part humanoids are used to represent characters like Players let's say we want to get the humanoid of a player named John we could local player equals game dot players colon fine for his child John okay and then to find the humanoid we do local humanoid equals player dot character and then we want to find first child of class humanoid and this will only work in a local script so if the game player if wanted to find the game player we would do this if you want to find the actual player who's playing we would do game.players dot local player this would only run in a local script now we can access the humanoids properties and methods the object browser in Roblox Studio lets you see all the available classes and and their properties methods and events it's a great tool when you're learning the script and even when you're season scripter don't forget to use it it is on view and you go to you go to the object browser it shows you all the objects that exist into Roblox Studio Loops allow us to perform a block of code multiple times there are different types of Loops in Lua such as for Loops while loops and repeat until Loops for Loops are perfect and we know how many times we want to Loop here's an example 4i equals 1 comma five do we do print I it's gonna print one two three four five this will print the numbers one through five in a loop while Loops keep looping as long as the condition is true for example we could do local num equals one then we could do while num is less than or equal to five then do we're going to print num I'm going to do num equals num plus one okay this will print the numbers one through five we can stop a loop prematurely with the break keyword let's say we want to stop our previous loop at three we could do local num equals one while num is less is less than or equal to five do if is equal equal to 3 then we're going to break and then we're going to print the number and then num plus num num equals num plus one this will print the numbers one and two that's next let's go over debris service the debris service lets us automatically clean up instances after a certain time here's how we use it local parts we do local part as a local variable you do instance dot new part okay let's do part dot parent equals workspace and then game get service debris and then we're gonna do add item Parts five this creates a new part and adds us the workspace then deletes it after five seconds tables and Lua are used to store multiple values they're similar to arrays on lists or any other language for example we could do local table my table equals we could do curly brackets one two three four five okay and then this table stores the numbers one through five we can also use tables to store key value pairs for example we could do local fruit colors equals and we could do this curly brackets Apple equals red comma banana equals yellow okay remember the Roblox developer Hub is your best friend if you're stuck or need more information about a function event or class it's the place to go you can find articles API references and tutorials there by creating compelling experiences and games on Roblox you can monetize your work with in-game purchases and game passes you create these using scripting and then players can buy them with Robux always strive to add value with your scripts and players will appreciate it I go over all these topics inside of my full course on quizgraded.com if you'd like to go check that out go check it out but let's go on to the next part Vector three Basics Vector three is used to represent 3D positions or direct for example to set the position of a part you might do this part dot position equals vector3. new zero ten zero this sets the parts position 10 studs above the origin inheritance allows us to create a new script that has all the key abilities of an existing script plus more Lua doesn't support indents directly but we can simulate it with meta tables this is a more advanced topic so you might want to look it up on the dev Hub callbacks are functions you can pass to another function to be executed later here's an example using the touched event we could do local function on touch we do print print heart touched part touch and then we can do part dot touch connect untouched untouched is a callback function that gets called when the part is touched P call stands for protected call it calls a function and catches any errors that occur for example to do a p call we would do local success comma air equals P call function and then we would do air this is an error okay P call returns two values a bull Boolean indicating success and the error message if there was one Lua has built-in functions for getting the current time and date such as os.time and os.date you can use these to create time-dependent behaviors in your scripts meta tables and meta methods in Lua let you define custom behavior for tables like when you have what happens when you have two tables together this is another Advanced topic so look up in the dev Hub if you're interested debugging strategies debugging is an important part of scripting always test your scripts and use print statements or the warn statements or the debugger to find problems and remember the error message is your friend it tells you what went wrong and aware good performance is crucial for a smooth gaming experience to optimize your scripts avoid unnecessary calculations use Advanced instead of polling and keep your clean code clean and organized I teach all this in my complete Lua learn course on quizgrid.com scripts on Roblox run either on the server or the client server scripts control the game mechanics while local scripts went on the player's device and control things like the player's guis it's important to understand which script to use for what purpose modules in Lua let you split up your code into reusable parts to create a module you can return a table of functions from a script and you can require that script by using the acquire statement so require and we can do the script and then we can do dots we can find a script inside right so if the script was called my script we could do my script and you can use those functions inside of the other script next let's go over Advanced scope underscore G and underscore EnV underscore G and underscore EnV are special tables in lieu of the deal with scope G is the global environment so G underscore G is the global environment okay and underscore EnV is the current environment so underscore EnV okay understanding these can help you write cleaner and safer code core routines and Lua lets you pause and resume execution of a function they can be used more efficient and responsive scripts but they're also an advanced topic and it can be difficult to use correctly so I go over that in my full course objects in Roblox have many properties that control their behavior it's worth familiarizing yourself with these properties in the object browser understanding them can help you get more specificated scripts and games by going to the do Tab and going to object browser Roblox allows you to make HTTP requests to external servers letting you use external apis to enhance your game for example you could use an API to fetch weather data and user control the weather in your game if you want to enable HTTP Services we can go to our settings we can go to our game settings and we need to save our tour game to Roblox first after we save it we're going to open it up now if we go to our game settings I mean go to our security tab we can turn on HTTP requests right here and click save raycasting is a technique for detecting intersections between a line or Ray and objects in your game it's used for things like shooting bullets casting shadows and more you can check out the full tutorial right here above this the info the info of the screen I made a complete video how to discuss how to actually use raycasting remotes and remote functions are used to communicate between server and client scripts they're crucial for creating multiplayer experiences where players can interact with each other in the game world and also that video is on my channel you guys go check that out right here scripting security best practices script security is crucial when scripting always validate input from the client on the server use secure functions for handling data and never expose sensitive information in your scripts in case it gets leaked or in case someone fully reads the file scripting Indian development are always involving stay curious keep learning and who knows when your scripting Journey will take you building and scripting go hand in hand in Roblox good integration between your building and your scripts make can make your games more interactive and engaging scripting isn't just a one and done process as Roblox updates and new features aren't added it's important to update and maintain your scripts to ensure they work properly that's it for this introduction to scripting it's a big topic but don't be intimidated keep practicing keep learning and remember you're capable of creating amazing things if you want to learn even more go check out quizgrid.com Link in the description you guys can get a complete guide to Roblox Lua and Roblox scripting and that wraps up our session thanks for joining in let's give a shout out to everyone who made this possible our organizers everyone who supports this Channel and of course all of you for making this effort to learn and grow happy scripting everyone Roblox coach
Info
Channel: TheRobloxCoach
Views: 24,560
Rating: undefined out of 5
Keywords: programming, programming roblox, coding, roblox studio, lua, roblox lua, game development, roblox scripting tutorial, scripting, roblox, lua tutorial, how to script on roblox, chatgpt, gamedev, game dev, roblox studio tutorial, chatgpt roblox, roblox advanced scripting tutorial, how to easily script, roblox object oriented programming, roblox script, roblox studio scripting, developing on roblox easily, script on roblox, script on roblox studio, scripting on roblox free
Id: ycAblH93RDA
Channel Id: undefined
Length: 17min 54sec (1074 seconds)
Published: Mon Jul 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.