The ContextActionService service has methods for making sure your game is cross-platform compatible!
Did you know
FindFirstChild has a second, optional, parameter which will search through every descendant?
Don't understand an error message? Try this wiki page!
Use Ctrl+Shift+F in Studio to search through all scripts in your game at once!
The Died event is the best way to do things upon a player's death.
Writing one function is quicker than writing the same code twice. (Credit to CodeTheorem)
Pressing F9 in game will display the developer console which can be used to see the output in a running game. (Credit to FearMeIAmLag)
Use the GetFullName method to get the full hierarchy of any object, in standard Lua syntax!
] The JumpPower property of Humanoids allows you to set how high a Character can Jump!
For games that use network filtering, you'll have to use RemoteEvents and RemoteFunctions to communicate between the server and the clients.
If you do not eventually yield inside of a while loop, it'll crash your game.
To use HttpService, you must have HttpEnabled set to true!
The Kick() method has an optional parameter to display a message.
In games with FilteringEnabled set to true, any changes you make outside of the player, in a LocalScript, will remain local, and will not show on the server.
Using the method wait() rather than connect() on an event will cause your script to wait until the event has occurred.
Call any function via the
pcall function to catch errors and continue script execution!
Remember DRY: Don't Repeat Yourself. Instead of writing the same code twice, always write a function that executes the same thing. It'll save you time and make your code more readable!
It's important to use indentations to space out your code. Code that isn't tabbed is extremely messy and difficult to understand! You should use one additonal indentation for every new code block.
To maintain security in your FilteringEnabled game, never trust anything the client sends you. Always check to see if the data the client is sending you makes sense and is possible. Being good at network security is never trusting anything anyone sends you.
To make smooth animations, use RenderStepped along with an easing function based on the current time with tick. Never use for loops with a simple wait in between each iteration!
Did you know: There's a language called Moonscript that compiles into Lua, and has many features Lua lacks such as classes (OOP), significant whitespace, string interpolation, and table comprehensions!
Lua functions are just like any other variable value. You can pass functions around just like you can variables to create some cool callback magic!
You can use unpack to unpack a table into a tuple, which allows you to return multiple values from a function easily from a table.
To quickly put the arguments of a variadic function into a table, simply use
Lua supports hexadecimal literals, e.g.
local x = 0x18 will set
x to be equal to
Think about how much your code actually needs to run: You probably don't need your zombie AI to recalculate its target every single frame, or checking if a player is within a certain range every frame. These operations only need to take place every second or so, and this will reduce latency in your game!
Try to send as little data to the client as possible in order to speed up your game. Keep all models, tools, and maps that aren't in use in ServerStorage.
You can't actually execute two blocks of code at the same time in a ROBLOX game, all code in ROBLOX runs consecutively, even code in two separate scripts. If you're attempting to use coroutines (or spawn, delay) then make sure you know how they actually work!
Lighting is not intended for storage. Use ServerStorage, or ReplicatedStorage depending on your intention, if you need to hold objects. Use Lighting for skyboxes and post effects.
KeyDown is deprecated and should not be used in new works. Instead, use UserInputService or ContextActionService
Model:TranslateBy() is a resource-friendly smooth position changer, as opposed to a for loop to CFrame a part.
Instead of using Color3.new(r/255,g/255,b/255), use Color3.fromRGB(r,g,b) to use actual RGB values!
:connect, :disconnect and :wait are deprecated! Use :Connect, :Disconnect and :Wait instead!
By using Ctrl+H you are able to search and/or replace words, within a script.
:remove() is deprecated, use :Destroy() instead.
Instead of using an infinite loop, see if you can connect the code to an event.
If you can't explain the purpose of your complicated code in a few sentences, you're probably doing it wrong.
Most of the Data Constructors in Roblox support more than one method to construct that data type. Using the correct constructor for your needs can simplify your code.
The MicroProfiler is a advanced tool to analyze and debug client-side performance problems. Additional information about the MicroProfiler can be found here.
You can use the IsTenFootInterface method of GuiService to determine whether or not a player is playing on a console.
If you want to clone a table from one variable to another, don't do t2 = t1, that will affect to t2 when t1 is changed. Instead create a function that clones values from a table to another.
The Parent parameter for Instance.new is deprecated as it can cause significant performance issues if used incorrectly. A new instance should first be setup then parented to the game to minimize the resources required to replicate each state change throughout the game. More information can be found here.
Along with printing, you can also use
Chapters 16.0-16.2 contain everything you need to know about creating custom classes with metatables.