ebook img

Mastering Roblox Coding: The unofficial guide to leveling up your Roblox scripting skills and building games using Luau programming PDF

424 Pages·2022·10.986 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Mastering Roblox Coding: The unofficial guide to leveling up your Roblox scripting skills and building games using Luau programming

Mastering Roblox Coding The unofficial guide to leveling up your Roblox scripting skills and building games using Luau programming Mark Kiepe BIRMINGHAM—MUMBAI Mastering Roblox Coding Copyright © 2022 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Group Product Manager: Rohit Rajkumar Publishing Product Manager: Ashitosh Gupta Senior Editor: Aamir Ahmed Senior Content Development Editor: Rakhi Patel Technical Editor: Shubham Sharma Copy Editor: Safis Editing Project Coordinator: Sonam Pandey Proofreader: Safis Editing Indexer: Subalakshmi Govindhan Production Designer: Shankar Kalbhor Marketing Coordinator: Elizabeth Varghese First published: August 2022 Production reference: 1290722 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-80181-404-1 www.packt.com Co n t r i b u t o r s About the author Mark Kiepe is an experienced Roblox Programmer and Game Designer with over six years of experience. He has contributed to several successful Roblox games. Besides these achievements, he is also the Co-Owner of a Roblox Game Studio called Sarcastic Studios, with games such as Pet Store Tycoon and Dream Island. Mark has contributed to more than 150 million play sessions across all games at the time of writing. Mark started as a self-taught programmer on Roblox. What he learned on Roblox helped him in college. He currently attends a University of Applied Sciences in The Netherlands, where he studies Software Development. I want to thank my parents and brother for their continuous support while writing this book. I am incredibly grateful for the amount of motivation they have given me. Thanks to everyone at Packt for helping me write this book. It means the world to me. I want to give a special thanks to Aamir and Rakhi. I have learned so much about writing through your feedback that I would have never accomplished without them. I would also like to thank Vaideeshwari for giving me the opportunity to write this book. About the reviewers Arnav is a UGC Event Organizer working alongside DevRel for Roblox. He has hosted numerous events on the platform and is also an experienced developer. He has over 350 million contributed visits. He is known by his Roblox username “AceDevArnav” and is also the owner of Ace Developing Studios , which is one of the rising studios on Roblox with its upcoming games and UGC items. Mir Ali was born in Karnataka, India on June 4, 1983. He studied in Dubai, UAE. He learned programming from the 6th Grade, starting with Q Basics, and then learning C and C++. He found these boring, as there was no way to visualize the results, and nothing made sense to him back then, except for a few ways of using IF statements, and a calculator that he made himself. He also couldn’t quite figure out what the lines of code were, when they started, or what OOP was. He therefore called it quits on programming and took a journey into building Gaming PC and servers. He then did his Cisco certification and went deeper to configure ATM relays and protocols, and calculate IP addresses for big companies. Years passed by, and he became a father. One day his son came to him and asked, "Father, what is LUA, and how do you make an obby with rotating parts?" Mir Ali saw hope in his son’s eyes, and got up, opened Roblox, and started teaching him. He taught his son IF conditions and operators, which were easy until he reached a syntax “:”, which was from OOP. This was when lightning struck him, and everything made sense. He taught his son a full library of LUA, including Bitwise operations, and made his own Physics and network library from scratch. Now, instead of his son, Mir Ali teaches corporate giants such as Accenture, Vodafone, Microsoft, and Walmart, to name but a few. He teaches the procedural generation of buildings and environments with complex floors, and ways to enter them. He also teaches Deep math and trigonometry, such as how to make your own Math library. Last but not least, Mir Ali teaches M.L and A.I. To my children, Arafath, Ishan, Hasanath, and Saleyhath, who motivated me. Table of Contents Preface Part 1: Start Programming with Roblox 1 Getting Up to Speed with Roblox and Luau Basics Technical requirements 3 Lower and upper camel case 16 Understanding Roblox and Luau 4 Updating variables 16 Removing magic numbers 18 Creating an account 4 Introducing constants 19 Introducing Luau 5 Using conditionals 21 Understanding and using data types in Luau 6 Relational operators 21 if-else conditionals 22 Creating a script 6 Using elseif 24 Hello, world! 7 Nested if statements 25 Numbers 8 Math operations 9 Understanding scopes 28 Combining math operations 10 Exercise 1.1 – Changing properties String concatenation 11 on a part 30 Escape characters 11 Exercise 1.2 – Police system part I 34 Casting data types 12 Exercise 1.3 – Understanding a script 35 Booleans 13 Summary 37 Logical operators 13 Introducing and using variables 15 vi Table of Contents 2 Writing Better Code Technical requirements 39 Functions in a table 62 Using functions 40 Programming loops 63 Making a function 41 while loops 63 Parameters and arguments 42 repeat until loops 65 Multiple parameters 44 for loops 66 Default parameter values 45 Continuing and stopping a loop 67 Returning functions 47 Large oops 71 Multiple return values 49 Using modules 72 Nested functions 50 Creating a module script 72 Best practices when using functions 52 Requiring the module from another script 74 Storing data types in tables 53 Exercise 2.1 – simple elevator 75 Storing data in a table 53 Exercise 2.2 – converting loops 75 Reading data from a table 54 Setting data in a table 55 Exercise 2.3 – Police System II Using dictionaries 57 (difficult) 76 Multi-dimensional tables 58 Summary 78 3 Event-Based Programming Technical requirements 81 Using bindable functions 96 Introduction to events 82 Comparing events to modules (advanced) 100 Using bindable events in modules (advanced) 100 Functions on instances 82 Listening to events 85 Exercise 3.1 – event-based game 103 Using properties for missing events 88 Summary 106 Creating custom events 92 Using bindable events 92 Table of Contents vii Part 2: Programming Advanced Systems 4 Securing Your Game Technical requirements 109 Implementing security 129 Understanding the client and server 110 Server checks 130 Introducing LocalScripts 110 Implementing debounces 131 FilteringEnabled 113 Honeypots 134 Replication exceptions to FilteringEnabled 114 Filtering user text 135 Client and server responsibilities 116 TextObject 136 Using RemoteEvents and The GetNonChatStringForBroadcastAsync RemoteFunctions 118 function 138 The GetChatForUserAsync function 141 Setting up the GUI 118 Client-sided Team Changer 119 Exercise 4.1: Securing your game 142 Using RemoteEvents 121 Exercise: 142 Using RemoteEvents from the server Summary 144 to the client 124 Using RemoteFunctions 126 5 Optimizing Your Game Technical requirements 147 Working with tweens 168 Understanding and using Setting up the gate 168 StreamingEnabled 148 Setting up the server scripts 170 Enabling StreamingEnabled 148 Getting tween data 172 Programming with StreamingEnabled 150 Understanding TweenInfo 173 Creating a tween 174 Working with animations 159 Client-sided debounces 176 Uploading animations 159 Custom yielding functions 178 Understanding the Animator object 160 Exercise 5.1 – greeting an NPC 180 Programming an AnimationTrack 161 Animations on NPCs 164 Exercise 5.2 – falling block 182 Summary 184 viii Table of Contents 6 Creating User Interfaces for All Devices Technical requirements 185 Working with color-blindness 210 Creating GUIs 186 Displaying controls 211 Improving GUI navigation 212 Using ScreenGuis 186 Using images 213 Using SurfaceGuis 199 Using Tweens 214 Using BillboardGuis 205 Core GUIs 217 Optimizing UIs 208 Exercise 6.1 – Creating a shop GUI 218 Testing GUIs 209 Summary 221 Small UI improvements 210 7 Listening to User Input Technical requirements 223 Gamepad input 244 Working with ClickDetectors 224 Mouse input 250 Working with ProximityPrompts 231 ContextActionService 255 Working with tools 238 Choosing how to listen to user input 263 Implementing advanced user input 240 Exercise 7.1 – Eating food 265 Keyboard input 241 Summary 269 8 Building Data Stores Technical requirements 271 Removing data 293 Introduction to data stores 272 Writing safer data stores 295 Saving data 272 Caching data 295 Error handling 275 Autosaving 299 Reading data 276 Improving error handling 300 Creating default player data 278 Data store limitations 302 Saving tables 287 Creating a DataManager 304 Saving dictionaries 290 Setting versus updating data 306 Saving user data in data stores 291 Table of Contents ix Working with ordered data stores 309 Exercise 8.2 – Simple obby 316 Exercise 8.1 – Building and testing Summary 318 data stores 312 9 Monetizing Your Game Technical requirements 321 Working with PolicyService 341 Programming game passes 322 Giving Premium Benefits 343 Prompting game passes 323 Implementing Premium Benefits 344 Rewarding game passes 326 Third-party sales 346 Instant game pass reward 329 Implementing third-party sales 348 Implementing developer products 332 Exercise 9.1 – building a currency Prompting developer products 334 system 350 Rewarding developer products 335 Summary 352 Part 3: Creating Your Own Simulator Game 10 Creating Your Own Simulator Game Technical requirements 357 Implementing rebirths 377 Introduction to the game 358 Selling orbs 380 Creating data stores 361 Programming GUIs 382 Getting keys for our data stores 361 Programming the SideButtons GUI 383 DataManager functions 363 Programming the Rebirthing GUI 385 DataManager events 364 Programming the DeveloperProducts GUI 387 Programming the GamePasses GUI 389 Implementing server scripts 366 Programming the Upgrade GUI 390 Implementing leader stats 366 Implementing monetization scripts 368 Updating your game 391 Implementing character upgrades 370 Summary 392 Claiming orbs 375

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.