Coding with Roblox Lua in 24 Hours PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This guide provides a comprehensive overview of Roblox Lua programming. It covers topics such as installing Roblox Studio, creating scripts, working with parts, and more in an easy-to-understand format.
Full Transcript
The Official Guide Coding with Roblox Lua 24 in Hours Coding with Roblox Lua in 24 Hours: The Official Roblox Guide Editor-in-Chief Copyright © 2022 by Roblox Corporation. “Roblox,” the Rob...
The Official Guide Coding with Roblox Lua 24 in Hours Coding with Roblox Lua in 24 Hours: The Official Roblox Guide Editor-in-Chief Copyright © 2022 by Roblox Corporation. “Roblox,” the Roblox logo, and “Powering Imagination” Debra Williams are among the Roblox registered and unregistered trademarks in the U.S. and other countries. All Cauley rights reserved. All rights reserved. This publication is protected by copyright, and permission must be obtained Acquisitions Editor from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmis- Kim Spenceley sion in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Editorial Services Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/ The Wordsmithery permissions/. No patent liability is assumed with respect to the use of the information contained LLC herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for dam- Managing Editor ages resulting from the use of the information contained herein. Sandra Schroeder ISBN-13: 978-0-13-682942-3 Senior Project ISBN-10: 0-13-682942-2 Editor Library of Congress Control Number: 2021948694 Tonya Simpson ScoutAutomatedPrintCode Copy Editor Trademarks Charlotte Kughen All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Pearson cannot attest to the accuracy of this information. Use of a term Indexer in this book should not be regarded as affecting the validity of any trademark or service mark. Cheryl Lenser Warning and Disclaimer Proofreader Every effort has been made to make this book as complete and as accurate as possible, but no Sarah Kearns warranty or fitness is implied. The information provided is on an “as is” basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any Editorial Assistant loss or damages arising from the information contained in this book. Cindy Teeters Special Sales Cover Designer For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, Chuti Prasertsith training goals, marketing focus, or branding interests), please contact our corporate sales depart- Compositor ment at [email protected] or (800) 382-3419. Bronkella For government sales inquiries, please contact [email protected]. Publishing LLC For questions about sales outside the United States, please contact [email protected]. Graphics Processing TJ Graham Art Pearson’s Commitment to Diversity, Equity, and Inclusion Pearson is dedicated to creating bias-free content that reflects the diversity of all learners. We embrace the many dimensions of diversity, including but not limited to race, ethnic- ity, gender, socioeconomic status, ability, age, sexual orientation, and religious or political beliefs. Education is a powerful force for equity and change in our world. It has the potential to deliver opportunities that improve lives and enable economic mobility. As we work with authors to create content for every product and service, we acknowledge our responsibility to demonstrate inclusivity and incorporate diverse scholarship so that everyone can achieve their potential through learning. As the world’s leading learning company, we have a duty to help drive change and live up to our purpose to help more people create a better life for themselves and to create a better world. Our ambition is to purposefully contribute to a world where: Everyone has an equitable and lifelong opportunity to succeed through learning. Our educational products and services are inclusive and represent the rich diversity of learners. Our educational content accurately reflects the histories and experiences of the learners we serve. Our educational content prompts deeper discussions with learners and motivates them to expand their own learning (and worldview). While we work hard to present unbiased content, we want to hear from you about any con- cerns or needs with this Pearson product so that we can investigate and address them. Please contact us with concerns about any potential bias at https://www.pearson.com/ report-bias.html. Contents at a Glance Hour 1 Coding Your First Project.............................................................. 1 2 Properties and Variables............................................................. 17 3 Creating and Using Functions..................................................... 31 4 Working with Parameters and Arguments................................... 43 5 Conditional Structures................................................................ 57 6 Debouncing and Debugging....................................................... 73 7 while Loops............................................................................. 91 8 for Loops............................................................................... 101 9 Working with Arrays................................................................ 113 10 Working with Dictionaries........................................................ 127 11 Client Versus Server................................................................. 145 12 Remote Events: One-Way Communication................................. 161 13 Using ModuleScripts................................................................. 173 14 Coding in 3D World Space....................................................... 187 15 Smoothly Animating Objects.................................................... 199 16 Solving Problems with Algorithms............................................. 209 17 Saving Data............................................................................ 219 18 Creating a Game Loop............................................................. 229 19 Monetization: One-Time Purchases........................................... 243 20 Object-Oriented Programming.................................................. 259 21 Inheritance............................................................................. 271 22 Raycasting.............................................................................. 287 23 Plopping Objects in an Experience: Part 1.................................. 297 24 Plopping Objects in an Experience: Part 2.................................. 313 Appendix A Roblox Basics.......................................................................... 321 Index...................................................................................... 355 Table of Contents HOUR 1: Coding Your First Project 1 Installing Roblox Studio............................................................................. 1 Let’s Take a Tour....................................................................................... 2 Opening the Output Window...................................................................... 5 Writing Your First Script.............................................................................. 6 Error Messages......................................................................................... 11 Leaving Yourself Comments...................................................................... 12 HOUR 2: Properties and Variables 17 Object Hierarchy...................................................................................... 18 Keywords................................................................................................. 19 Properties................................................................................................ 20 Finding Properties and Data Types............................................................ 22 Creating Variables................................................................................... 22 Changing the Color Property.................................................................... 25 Instances................................................................................................. 26 HOUR 3: Creating and Using Functions 31 Creating and Calling Functions................................................................. 31 Understanding Scope................................................................................ 33 Using Events to Call Functions.................................................................. 33 Understanding Order and Placement......................................................... 36 HOUR 4: Working with Parameters and Arguments 43 Giving Functions Information to Use......................................................... 43 Working with Multiple Parameters and Arguments..................................... 45 Returning Values from Functions............................................................... 49 Returning Multiple Values........................................................................ 50 Returning Nil........................................................................................... 51 Dealing with Mismatched Arguments and Parameters................................ 51 Working with Anonymous Functions......................................................... 52 vi Coding with Roblox Lua in 24 Hours HOUR 5: Conditional Structures 57 if/then Statements................................................................................. 58 elseif................................................................................................... 62 Logical Operators..................................................................................... 62 else....................................................................................................... 63 HOUR 6: Debouncing and Debugging 73 Don’t Destroy, Debounce.......................................................................... 73 Figuring Out Where Things Go Wrong....................................................... 82 HOUR 7: while Loops 91 Repeat Forever, while true do............................................................... 91 Some Things to Keep in Mind.................................................................... 92 while Loops and Scope............................................................................ 98 HOUR 8: for Loops 101 How for Loops Work............................................................................. 102 Nested Loops......................................................................................... 109 Breaking Out of Loops............................................................................ 110 HOUR 9: Working with Arrays 113 What Are Arrays?.................................................................................. 113 Adding Items Later................................................................................. 114 Getting Information from a Specific Index............................................... 114 Printing an Entire List with ipairs()..................................................... 115 Folders and ipairs()............................................................................ 116 Finding a Value on the List and Printing the Index................................... 121 Removing Values from an Array............................................................. 122 Numeric for Loops and Arrays............................................................... 123 HOUR 10: Working with Dictionaries 127 Intro to Dictionaries............................................................................... 127 Adding and Removing from Dictionaries................................................. 130 Removing Key-Value Pairs...................................................................... 130 Working with Dictionaries and Pairs....................................................... 132 Returning Values from Tables................................................................. 133 Contents vii HOUR 11: Client Versus Server 145 Understanding the Client and the Server.................................................. 145 Working with GUIs................................................................................. 146 Understanding RemoteFunctions............................................................. 149 Using RemoteFunctions.......................................................................... 149 HOUR 12: Remote Events: One-Way Communication 161 Remote Events: A One-Way Street............................................................ 161 Communicating from the Server to All Clients.......................................... 162 Communicating from the Client to the Server.......................................... 165 Communicating from the Server to One Client......................................... 170 Communicating from Client to Client...................................................... 171 HOUR 13: Using ModuleScripts 173 Coding Things Just Once........................................................................ 173 Placing ModuleScripts............................................................................ 174 Understanding How ModuleScripts Work................................................. 174 Naming ModuleScripts........................................................................... 174 Adding Functions and Variables.............................................................. 175 Understanding Scope in ModuleScripts..................................................... 176 Using Modules in Other Scripts................................................................ 177 Don’t Repeat Yourself............................................................................. 183 Dealing in Abstractions.......................................................................... 183 HOUR 14: Coding in 3D World Space 187 Understanding X, Y, and Z Coordinates................................................... 187 Refining Placement with CFrame Coordinates.......................................... 189 Offsetting CFrames................................................................................. 191 Adding Rotations to CFrames.................................................................. 191 Working with Models............................................................................. 192 Understanding World Coordinates and Local Object Coordinates............... 193 HOUR 15: Smoothly Animating Objects 199 Understanding Tweens........................................................................... 199 Setting TweenInfo Parameters................................................................ 201 Chaining Tweens Together..................................................................... 205 viii Coding with Roblox Lua in 24 Hours HOUR 16: Solving Problems with Algorithms 209 Defining Algorithms............................................................................... 209 Sorting an Array.................................................................................... 210 Sorting in Descending Order................................................................... 212 Sorting a Dictionary............................................................................... 213 Sorting by Multiple Pieces of Information................................................. 216 HOUR 17: Saving Data 219 Enabling Data Stores.............................................................................. 219 Creating a Data Store............................................................................. 220 Using Data in the Store.......................................................................... 220 Limiting the Number of Calls.................................................................. 225 Protecting Your Data.............................................................................. 225 Saving Player Data................................................................................ 226 Using UpdateAsync to Update a Data Store............................................. 226 HOUR 18: Creating a Game Loop 229 Setting Up Game Loops.......................................................................... 229 Working with BindableEvents................................................................. 230 HOUR 19: Monetization: One-Time Purchases 243 Adding Passes to Your Experience............................................................ 243 Configuring the Pass.............................................................................. 246 Prompting In-Game Purchases................................................................ 247 HOUR 20: Object-Oriented Programming 259 What Is OOP?........................................................................................ 259 Organizing Code and Projects................................................................ 259 Making a New Class.............................................................................. 260 Adding Class Properties.......................................................................... 261 Using Class Functions............................................................................. 263 HOUR 21: Inheritance 271 Setting Up Inheritance............................................................................ 272 Inheriting Properties............................................................................... 274 Working with Multiple Child Classes....................................................... 277 Contents ix Inheriting Functions............................................................................... 278 Understanding Polymorphism................................................................. 278 Calling Parent Functions....................................................................... 282 HOUR 22: Raycasting 287 Setting Up the Function to Raycast.......................................................... 287 3D Math Trick: Getting the Direction....................................................... 289 Setting Raycast Parameters..................................................................... 290 3D Math Trick: Limit Direction................................................................ 293 HOUR 23: Plopping Objects in an Experience: Part 1 297 Setting Up the Object.............................................................................. 298 Creating a Plop Button........................................................................... 302 Tracking Mouse Movements.................................................................... 303 Previewing the Object............................................................................. 307 HOUR 24: Plopping Objects in an Experience: Part 2 313 Detecting Mouse Input........................................................................... 314 Sending a Message to the Server.............................................................. 316 Getting the Message............................................................................... 317 APPENDIX A: Roblox Basics 321 Keywords............................................................................................... 322 DataType Index..................................................................................... 322 Operators.............................................................................................. 324 Naming Conventions............................................................................. 325 Animation Easing.................................................................................. 325 Possible Solutions to Exercises................................................................. 326 Index 355 About the Author Genevieve Johnson is the senior instructional designer for Roblox, the world’s largest user-generated social platform for play. In her role, she oversees creation of educational content and advises educators world- wide on how to use Roblox in STEAM-based learning programs. Her work empowers students to pursue careers as entrepreneurs, engineers, and designers. Prior to Roblox, Johnson was educational content manager for iD Tech, a nationwide tech education program that reaches more than 50,000 students yearly, ages 6-18. While at iD Tech, she helped launch a successful all-girls STEAM program, and her team developed educational content for more than 60 technology- related courses, teaching a variety of subjects from coding to robotics and game design. We Want to Hear from You! As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what we’re doing right, what we could do better, what areas you’d like to see us publish in, and any other words of wisdom you’re willing to pass our way. You can email or write to let us know what you did or didn’t like about this book—as well as what we can do to make our books better. Please note that we cannot help you with technical problems related to the topic of this book. When you email, please be sure to include this book’s title and author as well as your name, email address, and phone number. We will carefully review your comments and share them with the author and editors who worked on the book. Email: [email protected] Reader Services Register your copy of Roblox Game Development in 24 Hours at www.informit.com/register for convenient access to downloads, updates, and corrections as they become available. To start the registration process, go to informit.com/register and log in or create an account.* Enter the product ISBN (9780136829423) and click Submit. *Be sure to check the box that you would like to hear from us to receive exclusive discounts on future editions of this product. This page intentionally left blank HOUR 1 Coding Your First Project What You’ll Learn in This Hour: Why Roblox and Lua are a perfect combination What Roblox Studio’s main windows are How to say “Hello” to the world with your first code How to make a part explode How to check for errors How to leave a comment Roblox is the world’s most popular game development platform. All types of people come together to create amazing virtual experiences: artists, musicians, and—you guessed it—coders. Coding is what allows players to interact with the world that they see. In Roblox, the coding language used is Lua. Lua is one of the easiest coding languages to learn, and when used with Roblox Studio, you can see the results of your code fast. For example, want to create an enormous explosion with a massive blast radius? You can do that with just a couple of lines of Lua. Roblox Studio is the tool in which all Roblox games are created, and when paired with Lua, it offers seamless access to multiplayer servers, physics and lighting systems, world-building tools, monetization systems, and more. And even though Roblox provides the environment in which your program runs, you control the vision. You are the creator and artist. Roblox gives you the canvas and paints, and Lua the brushes and actions. But you, with some well-placed dabs of code, get to create your masterpiece. This first hour covers how to set up Roblox Studio, make your first script, and test your code. Installing Roblox Studio Before you get started, make sure you have Roblox Studio installed. It runs on Windows and MacOS, and you can grab a copy at https://roblox.com/create. Click Start Creating to begin. You’ll need to create a Roblox account if you don’t yet have one (see Figure 1.1). 2 HOUR 1: Coding Your First Project FIGURE 1.1 You need an account to use Roblox Studio. It’s free and just a quick sign-up away. Let’s Take a Tour Roblox Studio provides everything you need to create games. It includes assets such as character models, items to put in the world, graphics for the sky, soundtracks, and more. Go ahead and launch Roblox Studio to see the window shown in Figure 1.2. Enter the login infor- mation for the account you created when you signed up on the Roblox website and click Log In. FIGURE 1.2 Enter your normal Roblox account information. Let’s Take a Tour 3 When you first open up Studio, you see templates. These are starting places you can use for your experiences. The simplest starting point for any project is the Baseplate template. Click on the Baseplate template, as shown in Figure 1.3. FIGURE 1.3 Studio offers template places you can use as starting points. Let’s start with a quick overview of the main parts of the screen in Figure 1.4, and then move straight into your first line of code: 1. The offerings in the Toolbar ribbon change according to the menu tab you’ve selected. 2. The Toolbox contains existing assets to add to your game. You can also create your own assets through a 3D modeling program such as Blender3D, and Studio includes a set of mesh-editing tools to customize the 3D models already available. 3. The 3D Editor provides a view of the world. Hold your right mouse button to turn the view, and use the WASD keys to reposition the camera. Table 1.1 describes the different controls to move the camera. 4. The Explorer window provides convenient access to every key asset or system in the game. You use this to insert objects into your experience. 5. Use the Properties window to make changes to objects in the game, such as color, scale, value, and attributes. Select an object in the Explorer to see available properties. 4 HOUR 1: Coding Your First Project FIGURE 1.4 There are a number of panels, buttons, and lists in the Studio, and you’ll quickly become familiar with them. TABLE 1.1 Camera Controls Key Movement WASD Move the camera up, left, down, or right E Move the camera Q Lower the camera down Shift Move the camera slower Right mouse button (hold and drag mouse) Turn the camera Middle mouse button Drag the camera Mouse scroll wheel Zoom the camera in or out F Focus on selected object There are numerous ways to configure this main screen, including hiding different sections, rearranging their positioning to be more convenient, and changing their size. Roblox Studio is a very complete game development environment that goes well beyond Lua. It’s a big topic on its own, so you may want to check out our other book, Roblox Game Development in 24 Hours, for help. Opening the Output Window 5 Opening the Output Window The Output window in Studio isn’t open by default, but you need this before you continue so that you can see errors and messages that are related to your code. Use the following steps to display the Output window: 1. Click the View tab (see Figure 1.5). If you ever close a window and need to reopen it, you can find it here. FIGURE 1.5 Use the View tab to control which windows are open. 2. Click Output (see Figure 1.6) to display the Output window at the bottom of your screen, as shown in Figure 1.7. FIGURE 1.6 Click the Output option to open the Output window. FIGURE 1.7 The Output window opens beneath the 3D Editor. 6 HOUR 1: Coding Your First Project Writing Your First Script On to coding! You need something to hold your code, and that’s a script. You can insert scripts directly into objects within the world. In this case, you’re inserting a script into a part. Insert a Script into a Part A part is the basic building block of Roblox. Parts can range in size from very tiny to extremely large. They can be different shapes such as a sphere or wedge, or they can be combined into more complex shapes. 1. Return to the Home tab and click Part (see Figure 1.8). The part appears in the 3D Editor at the center of your camera view. FIGURE 1.8 Click Part on the Home tab to insert a part. 2. To add a script, in Explorer, hover over the part and click the + symbol, and then select Script from the drop-down menu (see Figure 1.9). FIGURE 1.9 You use Explorer to insert a script into the part. Writing Your First Script 7 TIP Finding Items Quickly Typing the first letter (S, in this case) or two of the items you are adding filters the list so you can locate that item quickly. The script automatically opens. At the top, you see words familiar to any coder: "Hello world!" (see Figure 1.10). FIGURE 1.10 The window shows the default script and code. Writing Some Code Since the 1970s, "Hello World!" has been one of the first pieces of code people have learned. Here it’s being used in the print function. Functions are chunks of code that serve a specific pur- pose. As you learn to code, you’ll use prebuilt functions like print(), which displays messages in the Output window. You will, of course, also learn how to create functions of your own. print() displays a string, which is a type of data usually used with letters and numbers that need to stay together. In this case, you’re printing "Hello world!": 1. Make this code your own by changing the message inside of the quotation marks to what you want for dinner tonight. Here’s an example: print("I want lots of pasta") 2. To test the code, in the Home tab, click Play (see Figure 1.11). 8 HOUR 1: Coding Your First Project FIGURE 1.11 Click Play to test your script. Your avatar will fall into the world, and you can see your dinner dreams displayed in the Output window, along with a note about which script that message came from (see Figure 1.12). FIGURE 1.12 The string is displayed in Output. 3. To stop the playtest, click the Stop button (see Figure 1.13). FIGURE 1.13 Click Stop to quit the playtest. 4. Return to your script by clicking on the tab above the 3D Editor, as shown in Figure 1.14. Writing Your First Script 9 FIGURE 1.14 Click Script to return to the window where your script is visible. Code an Explosion Code of course can do more than just display messages to the output window. It can completely change how players interact with the world and make it come alive. Let’s take a slightly longer piece of code and make the block in the Baseplate template destroy anything it touches: 1. Use the Move tool (see Figure 1.15) to move the block off the ground and away from the spawn point. The code you’re going to write will destroy anything it touches, and you don’t want it to go off prematurely. FIGURE 1.15 Move the part up and away from the spawn. 10 HOUR 1: Coding Your First Project 2. In the Properties window, scroll to Behavior and make sure Anchored (see Figure 1.16) is selected so the block doesn’t fall when you click Play. FIGURE 1.16 Check Anchored to keep the blocks from falling. 3. In the script, below the print function, add the following code: print("I want lots of pasta!") -- Destroys whatever touches the part local trap = script.Parent local function onTouch(partTouched) partTouched:Destroy() end trap.Touched:Connect(onTouch) NOTE Code Boxes Code boxes for this book will be presented in light mode, unless specifically calling attention to Studio UX. 4. Click Play and run up and touch the part. The result should be that your character breaks or parts of your avatar are destroyed. You may notice that this code only destroys what touches it directly, such as your feet. Try jumping on top Error Messages 11 of the block or brushing against it with just a hand. You’ll see only that part of your avatar is destroyed. The reason is that code only does what you tell it, and you told the part to destroy only what it touches and nothing more. You have to tell it how to destroy the rest of the player. Throughout this book, you’ll learn how to write additional instructions so that the code can handle more scenarios like this one. In Hour 4, “Parameters and Arguments,” you’ll learn how to make sure it destroys the entire player character. Error Messages What if the code didn’t work? The truth is, all engineers make mistakes in their code. It’s no big deal, and the editor and the output window can help you spot mistakes and fix them. Try mak- ing a couple of mistakes to learn how to better spot them later: 1. Delete the second parenthesis from the print function. A red line appears under local. (See Figure 1.17.) In the editor, red lines indicate a problem. FIGURE 1.17 A red line indicates Studio has spotted an error. 2. Hover over the red line, and the editor gives you a clue about what’s gone wrong, as shown in Figure 1.18. But don’t fix the mistake quite yet. 12 HOUR 1: Coding Your First Project FIGURE 1.18 An error message displays when you hover over the red line. 3. Click Play, which causes an error message to display in the Output window, as shown in Figure 1.19. Click the red error, and Studio takes you to where it thinks the problem is. FIGURE 1.19 The error shows up as a clickable red message in the Output window. Stop the playtest and fix the issue. TIP Changes Made While Playtesting Aren’t Permanent Be careful about making changes while in a playtest because the work you’ve done is not automati- cally saved. If you do make changes, be sure to click Preserve Changes when you stop the playtest. Leaving Yourself Comments In the previous code, you may notice the sentence -- Destroys whatever touches the part. This is a comment. Comments begin with two dashes. Anything on the same line as the dashes doesn’t affect the script. Q&A 13 Coders use comments to leave notes to themselves and others about what the code does. Trust us: When you haven’t looked at a piece of code in months, it’s very easy to forget what it does. The following code shows what it might look like to add a comment at the top of the script you wrote earlier in this hour: -- What do I want for dinner? print("I want lots of pasta!") Summary In just one hour, you’ve come a long way, particularly if this happened to be your first time cod- ing or using Roblox Studio. This hour covered creating an account and opening Roblox for the first time. By using the + button, you were able to insert a script into a part, and then you added code that turned the part into a trap for anyone who happened to touch it. In addition, you learned how to test code using the Play button and use the built-in error detec- tion within the script editor and Output window to help you troubleshoot when something goes wrong. Finally, you learned about comments, which are only readable in the script editor and can be used to leave notes about the purpose of the code. Q&A Q. Can you use Studio on a Chromebook? A. To create, Studio must be run on a MacOS or Windows machine. Once a game has been published, it’s available to be played on Android, Apple, Mac, PC, Chrome, and potentially even XBox Live. Q. How do I reopen a script if I close it? A. If you close out of the script editor, you can reopen it by double-clicking the script object in Explorer. Q. How do I save my work? A. Go to File, Publish to Roblox to save to the cloud, which makes your game accessible from any computer. Q. Where do I go if I want additional information about how Roblox Studio works? A. You can visit developer.roblox.com to find documentation on all of Studio’s features and API. 14 HOUR 1: Coding Your First Project Workshop Now that you have finished, let’s review what you’ve learned. Take a moment to answer the fol- lowing questions. Quiz 1. Roblox uses the _________ coding language. 2. Aspects of an object such as color, rotation, and anchored can be found in the ______ window. 3. Game objects are found in the _________ window. 4. To enable the Output window, which displays code messages and errors, enable it in the ________ tab. 5. True or false: Comments change the code to enable new functionality. 6. To force parts to stay in place, they need to be _______. Answers 1. Lua 2. Properties 3. Explorer 4. View 5. False. Comments do not affect the code and are used to leave notes to yourself and other coders as to the purpose of the script. 5. Anchored Exercise Before moving on, take a moment to experiment with the creation tools by creating a mini obsta- cle course. It could be individual parts the player has to avoid, or it could be a lava floor like the one shown in Figure 1.20. Exercise 15 FIGURE 1.20 Use what you’ve learned so far to create a lava obstacle course. Tips Create more parts and manipulate them with the Move, Translate, and Scale tools found on the Home tab (see Figure 1.21). You can also change the parts’ appearance with Material and Color. FIGURE 1.21 The Home tab has the tools you need to create and manipulate parts. Use a single large part and insert a script as you did earlier to turn it into lava. Additional models can be found in the Toolbox; just be aware that some models may already have scripts in them. Don’t forget to anchor all parts and models. If you know how to use the terrain tools, you can work that into your obstacle course as well. This page intentionally left blank Index Symbols 3D Editor, 3 3D space [ ] (brackets), in key-value pairs, CFrames, 189 128-129 offsetting, 191 : (colon) Position property, 190 accessing functions, 68 rotating with, 191 for function notation, 281 teleporting exercise, { } (curly brackets) 196-197, 341-342 for arrays, 113 models, positioning, 192 for dictionaries, 128 relative jumps example,. (dot operator) 194-195 for dictionary values, 129-130 world versus local coor- dinates, 193-194 for embedded objects, 47 X, Y, Z coordinates, 187-189 object hierarchy and, 18-19 properties and, 20 == (double equal sign) operator, 58 A = (equal sign), variable values, 22 >= (greater than or equal to) abstractions, 183-184 operator, 59 accessing __index, naming classes, 260 Data Stores, 220 "" (quotation marks), in key-value functions, 68 pairs, 128 ModuleScripts, 177-178, 182-183 356 adding adding anonymous functions, 52-55, 328 attributes, 64-67 class functions, 263-268 arguments checking values, 85 class properties, 261-263 definition of, 43 code reusability and, 79 items to arrays, 114 mismatched, 51-52 autocomplete feature, 20 key-value pairs to dic- multiple, 45-49 tionaries, 130-132 value types, 86 algorithms arithmetic operators, 324 for sorting B arrays alphabetically, 210-211 adding items, 114 Baseplate template, 3 arrays, 210 converting dictionaries to, BindableEvents, 230 ascending, 210-212 213-215 BindAction( ) function, 314 descending, 212-213 creating, 113-114 BindToRenderStep( ) function, dictionaries, 213-215, finding and removing all 303-305 218, 343 specific values, 123 blacklists versus whitelists in ray- mixed data types, 212 indexes, 113 casting, 310 multiple pieces of infor- finding from values, 121 blocks, anchoring, 10 mation, 216-218, 343 retrieving specific values, boolean data type, 22, 36 numerically, 211-212 114-115 brackets ([ ]), in key-value pairs, purpose of, 209-210 printing with ipairs( ) function, 128-129 alphabetical sorts, 210-211 115 break keyword, 110 anchoring blocks, 10 purpose of, 113 bridges and operator, 62 removing items, 122 reactivating, 38-40 animal sounds example (poly- searching part of, 123-124 solidifying, 42, 328 morphism), 279-282 sorting, 210 vanishing, 34-36 animation alphabetically, 210-211 burning fire, 93-97 CFrames, LoadCharacter( ) ascending, 210-212 buttons function versus, 241 descending, 212-213 for placing objects, creating, easing, 325 mixed data types, 212 302-303 tweens by multiple pieces of infor- testing, 170 chaining, 205-206 mation, 216-218, 343 viewing/hiding, 320 changing colors, 199-200, numerically, 211-212 buying items. See monetization; 208, 342 voting simulator, 133-142 Robux elevator doors example, ascending sorts, 210-212 202-205 assets, organizing, 231-234 setting parameters for, assigning variable values, 41 201-202 TweenService, 199 coordinates in 3D space 357 code organization with OOP, 259 C child objects, 18 searching, 223 collecting firewood, 100, 330-332 calling functions, 32 classes. See also child classes; colon (:) with events, 33-36 parent classes accessing functions, 68 parent functions, 282 calling parent functions, 282 for function notation, 281 camera, moving, 4, 321 creating, 260-261, 270, 346 color picker, 25 camouflage raycasting example, functions of, 263-268 colors, changing, 25, 199-200, 288-289 inheritance, 271-272 208, 342 car class example of functions, 278 comments, 12 adding properties, 262-263 job roles exercise, 285, concatenation, 23 property inheritance, 275-277 347 concatenation operator, 325 case-sensitivity of keywords, 19 multiple child classes, conditional structures, 57 277 elseif keyword, 62 cashing out Robux, 243 of properties, 274-277 else keyword, 63 CFrame.Angles( ) function, 191 setup, 272-274 if/then statements, 58-59 CFrames, 189 naming, 260 portals, creating, 63-70 LoadCharacter( ) function versus, 241 polymorphism, 278-282 configuring passes, 246-249 offsetting, 191 properties of, 261-263 connect( ) function, 33 Position property, 190 purpose of, 259 constants, 84 rotating with, 191 clients, 145 constructors, 260, 265 teleporting exercise, GUIs. See GUIs ContextActionService, 314-316, 196-197, 341-342 RemoteEvent object, 161-162 320 chaining tweens, 205-206 client-to-client communi- control variables in for loops, 103, changing cation, 171 111 gravity, 233 client-to-server communi- converting dictionaries to arrays, cation, 165-170 213-215 properties, 25 server-to-all-clients com- coordinates in 3D space changing seasons exercise, munication, 162-165 CFrames, 189 125-126, 334 server-to-single-client com- offsetting, 191 child classes, 271-272 munication, 170-171 calling parent functions, 282 Position property, 190 RemoteFunction object, function inheritance, 278 rotating with, 191 149-151 inheritance setup, 272-274 teleporting exercise, server/client divide, 149 multiple, 277 196-197, 341-342 store purchases, 151-158 polymorphism, 278-282 relative jumps example, cloning particle emitters, 100, 194-195 property inheritance, 274-277 330-332 world versus local, 193-194 X, Y, Z coordinates, 187-189 358 copying meshes copying meshes, 78 decals, inserting, 28-29, 327 doubling and halving variables, 85 countdowns, creating with descending sorts, 212-213 DRY coding. See also OOP RemoteEvent object, 163-165 descriptions, 255 abstractions, 183-184 crown sales example, 248-255 destroy( ) function, 18-19 purpose of, 183 curly brackets ({ }) detecting mouse input, 314-316 for arrays, 113 detector exercise, 295, 348 for dictionaries, 128 Developer Exchange Program, custom leaderboards, 87 243 E Developer Products, 256 easing in animation, 325 dictionaries elevator doors, creating, 202-205 converting to arrays, 213-215 D else keyword, 63 creating, 128 elseif keyword, 62 Damage Over Time (DoT), key-value pairs, 128 embedded objects, finding in 111-112, 333 adding, 130-132 hierarchy, 47 dance floor, creating, 92-93 formatting keys, 128-129 enabling Data Stores, 219 Data Stores removing, 130-131 end value in for loops, 103 accessing, 220 unique keys, 130 engagement payouts, 256 creating, 220 value usage, 129-130 equal sign (=), variable values, 22 enabling, 219 pairs( ) function, 132-133 error messages, 11-12 limiting network calls, 225 purpose of, 127-128 errors unique key names, 224 sorting, 213-215, 218, 343 list of, 228 updating, 220-228, 344 voting simulator, 133-142 string debugging, 82-84 data types, 22, 27 direction parameter for ray- event connections, order and in Lua, 322 casting, 289-290 placement, 138 in Roblox Studio, 323 distance, limiting for raycasting, events 293 debouncing BindableEvents, 230 doors, creating for elevator, Humanoid objects, 73-75, calling functions, 33-36 202-205 88-89, 330 RemoteEvent object, 161-162 DoT (Damage Over Time), with ProximityPrompts, 78-79 client-to-client communi- 111-112, 333 debugging cation, 171 dot operator (.) argument value types, 86 client-to-server communi- for dictionary values, 129-130 attribute values, 85 cation, 165-170 for embedded objects, 47 exercise, 88, 329 server-to-all-clients commu- object hierarchy and, 18-19 nication, 162-165 string debugging, 82-84 properties and, 20 server-to-single-client com- variable order and placement, double equal sign (==) operator, munication, 170-171 84 58 Touched, 34-35 functions 359 exercises teleporting with CFrames, generic, 115 animating color changes, 208, 196-197, 341-342 i in, 111 342 traps with ModuleScripts, numeric, 123-124 anonymous functions, 55, 185, 340-341 printing arrays, 115 328 updating player information, searching part of arrays, changing player speed, 72, 228, 344 123-124 328 Explorer window, 3 turning lights on/off, 116-121 changing seasons, 125-126, explosion script, 9-11 values in, 102-105 334 formatting dictionary keys, cloned particle emitters, 100, 128-129 330-332 collecting firewood, 100, F functions accessing, 68 330-332 false conditions, loops for, 98 anonymous, 52-55, 328 creating NPCs, 29, 327 files, saving, 13 arguments debouncing, 88-89, 330 filtering definition of, 43 debugging, 88, 329 lists, 7 mismatched, 51-52 detector with raycasting, 295, objects for raycasting, 294 multiple, 45-49 348 finding value types, 86 dictionary sorting, 218, 343 all specific array values, 123 BindAction( ), 314 DoT (Damage Over Time), 111-112, 333 array indexes from values, BindToRenderStep( ), 303-305 121 calling, 32 inserting decals, 28-29, 327 embedded objects in with events, 33-36 job roles, 285, 347 hierarchy, 47 loops, 112, 333-334 from parent classes, 282 list items, 7 map choice announcement, CFrame.Angles( ), 191 fire 172, 338-340 of classes, 263-268 burning, 93-97 NPC person class, 270, 346 connect( ), 33 collecting firewood, 100, obstacle course, 14-15, 326 constructors, 260, 265 330-332 pass creation, 257, 346 creating, 31-32 folders, modifying items placing objects, 311, 350 definition of, 31 with for loops, 116-121 player announcements, 242, destroy( ), 18-19 with ipairs( ) function, 116 345 GetAsync( ), 220, 225 for loops, 98, 101-102 price lists, 160, 336-338 IncrementAsync( ), 227 default increment, 105 rotating objects, 320, 351 inheriting, 278 examples and exercises, solidifying bridges, 42, 328 insert( ), 114 105-106, 112, 333-334 solutions to, 326-351 finding and removing all team assignments, 143, 334 specific array values, 123 360 functions ipairs( ) return values global variables, 22, 41 finding array indexes, 121 definition of, 49 glowing lights, 120 with folders, 116 multiple, 50, 80 goal value in for loops, 103 pairs versus, 142 nil, 51 gold ore script (mining simulator), printing arrays, 115 scope, 33, 37-38 79-82 LoadCharacter( ), 241 SetAsync( ), 220, 225 gold ore setup (mining simulator), 78-79 as methods, 33 table.sort( ), 210-213 graphical user interfaces. See in ModuleScripts tostring( ), 212 GUIs accessing, 177-178 UnbindAction( ), 314 gravity, changing, 233 adding, 175-176 UpdateAsync( ), 226-227 greater than or equal to (>=) scope, 176 wait( ), 42-43, 201 operator, 59 MoveTo( ), 264 default value, 86 grouping parts, 166, 192 multiple in scripts, 41 with while loops, 92-93 GUIs (graphical user interfaces) named, 52-55, 328 workspace:Raycast( ) creating, 106-109, 146-148, naming conventions, 32, 35, camouflage example, 335 69 288-289 customizing, 147 new( ), 26 direction parameter, moving, 154 order and placement, 36-40 289-290 purpose of, 146 paint( ), 44-48 limiting distance, 293 script placement, 148 pairs( ) setup, 287-288 with dictionaries, 132-133 ipairs( ) versus, 142 parameters G H creating, 43-45 Hello World! script, 7-9 definition of, 43 game loops hiding buttons, 320 maximum, 54 BindableEvents in, 230 hierarchy (of objects), 18 mismatched, 51-52 creating, 231-240 finding embedded objects, 47 multiple, 45-49 for player announcements, instances, 26 pcall( ), 225 242, 345 IntValue objects, 77 polymorphism, 278-282 purpose of, 229-230 naming conventions, 24 print( ), 7-9, 23, 43 gameplay, moving camera in, 321 properties, 20-22 for debugging, 82-84 generic for loops, 115 changing, 25 RemoteFunction object, GetAsync( ) function, 220, 225 data types for, 22, 27 149-151, 159 global coordinates, local versus, 193-194 variables and, 28 remove( ), 122 require( ), 177 LocalScript object 361 Humanoid objects, 59-61 inserting keywords, 19-20 changing player speed, 72, decals, 28-29, 327 break, 110 328 scripts into parts, 6-7 case-sensitivity, 19 debouncing, 73-75, 88-89, installing Roblox Studio, 1-2 else, 63 330 instances, 26 elseif, 62 VectorForce objects, adding, IntValue objects, 77 nil, 51 179-182 ipairs( ) function reserved names, 322 HumanoidRootPart, MoveTo( ) finding array indexes, 121 return, 49-50 function and, 264 with folders, 116 script, 20 pairs( ) versus, 142 type, 217 printing arrays, 115 workspace, 19 I iterations, 105 i as control variable, 111 if/then statements, 58-59 L ignoring objects in raycasting, J–K leaderboards 290-293 job roles exercise, 285, 347 creating, 75-77, 87 IncrementAsync( ) function, 227 jump pads maximum number of stats, 87 increment value in for loops, 103-105 creating, 178-183 value types, 86-87 indenting code, 32 relative jumps with, 194-195 leaderstats folder, 77 indexes, 113 length operator, 325 finding from values, 121 keys lights key-value pairs versus, 129 for moving camera, 321 colors, changing via tweens, uniqueness in Data Stores, 208, 342 retrieving specific values, 114-115 224 glowing, 120 in-game purchases. See moneti- key-value pairs, 128 SpotLight objects, 117 zation; Robux adding, 130-132 turning on/off, 116-121 inheritance, 271-272 in Data Stores, accessing, limiting of functions, 278 220 distance for raycasting, 293 job roles exercise, 285, 347 formatting keys, 128-129 network calls, 225 multiple child classes, 277 indexes versus, 129 lists, filtering, 7 overriding, 278-282 removing, 130-131 LoadCharacter( ) function, 241 of properties, 274-277 unique keys, 130 load times for scripts, 109 setup, 272-274 value usage, 129-130 local object coordinates, world insert( ) function, 114 versus, 193-194 LocalScript object, 148, 154-155 362 local variables local variables, 22, 184 Lua, 1 data types, 22, 27, 322 logging in to Roblox Studio, 2 arrays debugging logical operators, 62-63, 324 adding items, 114 argument value types, 86 loops converting dictionaries to, attribute values, 85 break keyword, 110 213-215 exercise, 88, 329 exercises, 112, 333-334 creating, 113-114 string debugging, 82-84 for false conditions, 98 finding and removing all variable order and specific values, 123 placement, 84 for, 98, 101-102 indexes, 113-115, 121 dot operator default increment, 105 examples, 105-106 printing with ipairs( ) for dictionary values, function, 115 129-130 finding and removing all purpose of, 113 for embedded objects, 47 specific array values, 123 removing items, 122 object hierarchy and, generic, 115 searching part of, 123-124 18-19 i in, 111 sorting, 210-213, properties and, 20 216-218, 343 functions. See functions numeric, 123-124 voting simulator, 133-142 keywords, 19-20 printing arrays, 115 classes. See also child loops searching part of arrays, classes; parent classes 123-124 break keyword, 110 calling parent functions, turning lights on/off, exercises, 112, 333-334 282 116-121 for false conditions, 98 creating, 260-261, 270, values in, 102-105 for, 98, 101-106, 111, 346 game loops 115-124 function inheritance, 278 BindableEvents in, 230 game loops, 229-242, 345 functions of, 263-268 creating, 231-240 nested, 109-110 inheritance, 271-274, for player announcements, repeat until, 237 285, 347 242, 345 while, 91-98 multiple child classes, 277 purpose of, 229-230 ModuleScripts naming, 260 nested, 109-110 accessing in scripts, polymorphism, 278-282 repeat until, 237 177-178, 182-183 properties of, 261-263 while, 91-92 code structure, 174 property inheritance, with ProximityPrompts, creating, 234-237 274-277 93-97 DRY coding and, 183 conditional structures, 57 scope, 98 functions and variables in, elseif keyword, 62 with wait( ) function, 92-93 175-176 else keyword, 63 jump pad example, if/then statements, 58-59 179-182 portals, creating, 63-70 monetization 363 naming, 174-175 indenting code, 32 models placing, 174 inserting into parts, 6-7 creating, 192 purpose of, 173 load times, 109 grouping parts into, 166 scope in, 176 for mining simulator, 79-82 positioning, 192 trap exercise, 185, multiple functions in, 41 modifying folder items 340-341 opening, 13 with for loops, 116-121 naming conventions, list of, order and placement in, with ipairs( ), 116 325 36-40 ModuleScripts object hierarchy, 18 renaming, 18-19 accessing in scripts, 177-178, finding embedded objects, saving, 13 182-183 47 strings, 7 code structure, 174 instances, 26 variables creating, 234-237 IntValue objects, 77 combining with strings, 23 DRY coding and, 183 naming conventions, 24, creating, 22-25 functions and variables in, 260 naming conventions, 24 175-176 properties, 20-22, 25, 27 properties and, 28 jump pad example, 179-182 variables and, 28 updating, 23 naming, 174-175 operators placing, 174 arithmetic, 324 purpose of, 173 concatenation, 325 scope in, 176 double equal sign (==), 58 M trap exercise, 185, 340-341 greater than or equal to monetization. See also Robux map choice announcement (>=), 59 exercise, 172, 338-340 Developer Products, 256 length, 325 map pickers, creating, 166-170 engagement payouts, 256 logical, 62-63, 324 meshes, copying, 78 ideas for, 256 most common, 58 messages passes purpose of, 324 receiving on server, 317-319 checking for ownership, relational, 324 252-255 sending to server, 316 reserved names, 322 configuring, 246-249 methods. See functions scripts, 6 creating, 244-245, 257, mining simulator, 75 autocomplete feature, 20 346 gold ore script, 79-82 comments, 12 crown sales example, gold ore setup, 78-79 DRY coding, 183-184 248-255 leaderboard, creating, 75-77 error messages, 11-12 prompting purchases, mismatched arguments/ explosion example, 9-11 247-250 parameters, 51-52 GUI script placement, 148 purpose of, 243 mixed data types, sorting, 212 Hello World!, 7-9 testing, 251-252 updating, 245 364 mouse input mouse input, detecting, 314-316 network calls, 225 placing, 297-298, 313. See mouse movements, tracking, Network Simulator, testing for also 3D space 303-306 multiple people, 138-139 creating button for, BindToRenderStep( ) function, new( ) function, 26 302-303 303-305 nil keyword, 51, 157 detecting mouse input, raycasting from mouse, 314-316 not operator, 62 305-306 with other object coor- NPCs (Non Playable Characters), MoveTo( ) function, 264 dinates, 190 17 moving previewing placement, adding face to, 28-29, 327 307-309 camera, 4, 321 creating, 23-25, 29, 327 receiving messages on GUIs, 154 exercise, 270, 346 server, 317-319 multiple arguments, 45-49 number data type, 22 second object exercise, multiple child classes, 277 numbers, sorting with strings, 212 311, 350 multiple functions in scripts, 41 numeric for loops, 123-124 sending messages to multiple parameters, 45-49 numerical sorts, 211-212 server, 316 multiple pieces of information, setup, 298-301 sorting by, 216-218, 343 tracking mouse multiple player interactions, movements, 303-306 variables for, 70 O purpose of, 259 multiple players, testing for, object hierarchy, 18 rotating 138-139 finding embedded objects, 47 with CFrames, 191 multiple return values, 80 instances, 26 while placing, 320, 351 IntValue objects, 77 obstacle course exercise, 14-15, 326 naming conventions, 24 N properties, 20-22 offsetting CFrames, 191 one-time purchases. See passes changing, 25 named functions, 52-55, 328 OOP (object-oriented pro- data types for, 22, 27 naming gramming) variables and, 28 classes, 260 classes. See also child object-oriented programming. ModuleScripts, 174-175 classes; parent classes See OOP (object-oriented pro- objects, 260 gramming) calling parent functions, naming conventions, 24, 32, 35, 282 objects 69 creating, 260-261, 270, filtering for raycasting, 294 constants, 84 346 ignoring in raycasting, constructors, 265 function inheritance, 278 290-293 list of, 325 functions of, 263-268 naming, 260 nested loops, 109-110 inheritance, 271-274, 285, 347 placing 365 multiple child classes, 277 or operator, 62 textures, showing activation, naming, 260 Output window, opening, 5 67 polymorphism, 278-282 overriding inheritance, 278-282 Touched event, 34-35 properties of, 261-263 passes property inheritance, checking for ownership, 274-277 252-255 purpose of, 259 P configuring, 246-249 code organization with, 259 creating, 244-245, 257, 346 paint( ) function, 44-48 objects crown sales example, pairs( ) function filtering for raycasting, 294 248-255 with dictionaries, 132-133 prompting purchases, ignoring in raycasting, ipairs( ) versus, 142 247-250 290-293 parameters purpose of, 243 naming, 260 creating, 43-45 testing, 251-252 placing. See placing, definition of, 43 objects updating, 245 maximum, 54 purpose of, 259 pcall( ) function, 225 mismatched, 51-52 rotating, 191, 320, 351 pet class example, adding multiple, 45-49 functions, 264-268 opening setting for raycasting, placing Output window, 5 290-293 models, 192 scripts, 13 for tweens, 201-202 ModuleScripts, 174 operating system requirements, parent classes, 271-272 13 objects, 297-298, 313. See calling parent functions from also 3D space operators child classes, 282 creating button for, arithmetic, 324 inheritance setup, 272-274 302-303 concatenation, 325 parent objects, 18 detecting mouse input, double equal sign (==), 58 ParticleEmitter objects, 72 314-316 greater than or equal to (>=), particle emitters, cloning, 100, with other object coor- 59 330-332 dinates, 190 length, 325 parts, 6 previewing placement, logical, 62-63, 324 colors, changing via tweens, 307-309 most common, 58 199-200 receiving messages on purpose of, 324 server, 317-319 creating instances, 26 relational, 324 rotating while, 320, 351 grouping, 166, 192 organizing second object exercise, initial location, 26 assets, 231-234 311, 350 inserting scripts into, 6-7 with OOP, 259 sending messages to ProximityPrompts for, 78-79 variables, 305 server, 316 366 placing setup, 298-301 ProximityPrompt objects, 64, RemoteEvent object, 161-162 tracking mouse 67-70 client-to-client communication, movements, 303-306 debouncing with, 78-79 171 player announcements exercise, with ServerScriptService, client-to-server communi- 242, 345 79-82 cation, 165-170 playerID, saving data with, 226 viewing, 268 server-to-all-clients communi- player management, services for, with while loops, 93-97 cation, 162-165 237-240 ProximityPromptService, 68-70 server-to-single-client commu- playtesting nication, 170-171 purchases. See monetization; changes during, 12 Robux RemoteFunction object, 149-151, 159 for multiple players, 138-139 remove( ) function, 122 references, checking, 165 removing scripts, 7-8 Q–R all specific array values, 123 polymorphism, 278-282 items from arrays, 122 portals, creating, 63-70 quotation marks ("") in key-value key-value pairs from dic- positioning. See placing pairs, 128 tionaries, 130-131 Position property (CFrames), 190 renaming scripts, 18-19 previewing object placement, raycasting renderstep, 303-305 307-309 camouflage example, 288-289 repeat until loops, 237 price list exercise, 160, 336-338 detector exercise, 295, 348 require( ) function, 177 PrimaryParts (models), 192 direction parameter, 289-290 reserved names, 322 print( ) function, 7-9, 23, 43 filtering objects, 294 resources for information, 13, for debugging, 82-84 from mouse, 305-306 319 printing arrays with ipairs( ) function setup, 287-288 retrieving specific array values, function, 115 limiting distance, 293 114-115 prompting in-game purchases, purpose of, 287 return keyword, 49-50 247-250 setting parameters, 290-293 return values properties, 20-22 through windows, 292-293 definition of, 49 changing, 25 whitelists versus blacklists, multiple, 50, 80 of classes, 261-263 310 nil, 51 data types for, 22, 27 reactivating bridges, 38-40 returning table values, 133 inheriting, 274-277 receiving messages on server, Roblox Premium variables and, 28 317-319 engagement payouts, 256 Properties window, 3 red lines in editor, 11-12 monetization and, 247 protected calls, 225 references, checking, 165 Roblox Studio, 1 relational operators, 324 blocks, anchoring, 10 relative jumps, creating, 194-195 camera controls, 4 scripts 367 data types, 323 parts, 6 saving scripts, 13 files, saving, 13 colors, changing via scope GUIs tweens, 199-200 of functions, 33, 37-38 creating, 106-109, creating instances, 26 in ModuleScripts, 176 146-148, 335 grouping, 166, 192 of variables, 41 customizing, 147 initial location, 26 of while loops, 98 moving, 154 inserting scripts into, 6-7 ScreenGui object, 146-147 purpose of, 146 ProximityPrompts for, script keyword, 20 script placement, 148 78-79 scripts, 6 Humanoid objects, 59-61 textures, showing acti- arrays vation, 67 changing player speed, adding items, 114 72, 328 Touched event, 34-35 converting dictionaries to, debouncing, 73-75, 88-89, red lines in editor, 11-12 213-215 330 resources for information, 13, creating, 113-114 VectorForce objects, 319 finding and removing all adding, 179-182 user interface, 2-4 specific values, 123 installing, 1-2 Robux. See also monetization indexes, 113-115, 121 leaderboards cashing out, 243 printing with ipairs( ) creating, 75-77, 87 engagement payouts, 256 function, 115 maximum number of stats, uses for, 243 purpose of, 113 87 rotating objects, 320, 351 removing items, 122 value types, 86-87 with CFrames, 191 searching part of, 123-124 leaderstats folder, 77 Run command, testing code, 48 sorting, 210-213, logging in, 2 216-218, 343 moving camera in, 321 voting simulator, 133-142 object hierarchy, 18 autocomplete feature, 20 finding embedded objects, S