Tip of the Day Suggestion Thread

  • Administrators

    Post any Tip of the Day suggestions here. They should be short and to the point, and convey useful and accurate information.


  • Can you add a list of the existing tips of the day.

  • Administrators

    Current Tips:

    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 24.

    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 warn(Message")

    Chapters 16.0-16.2 contain everything you need to know about creating custom classes with metatables.

  • Global Moderator

    [Tips Added]

    • :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.


  • If you need to disable certain Humanoid functions such as jumping, consider using SetStateEnabled.


    • Notably Vector3, Color3, and CFrame all have a method called :lerp() which lays the groundwork for interpolating each value type.
    • If you are having performance issues, micro-optimise your code to make it run as efficiently as possible.
    • Make sure to check if there's an already existing inbuilt method before making your own.

  • @TheDeadlyPanther On, "If you are having performance issues, micro-optimise your code to make it run as efficiently as possible.", I feel like micro-optimize could be changed to just optimize.

    Other than that, looks great!

  • Global Moderator

    @OldPalHappy Should be changed, even.


  • @OldPalHappy what confuses me is that @Link150 just gave me a lecture about the difference lol

    Because optimisation is not just performance issues.


  • [Tip Added]

    Here's one that ought to be shown.

    By using Ctrl+H you are able to search and/or replace words, within a script


  • Indenting your code is important! But why going through each line of a code block to indent if you can highlight the block of code you want to indent and press Tab?


  • When using listeners (:connect(function)) which include wait() remember to use debounce


  • @shabbs15 Why?


  • Well normally you should do it anyway but on when it includes wait() you should do it because the rest of the code wont run properly. I am not sure why.


  • :SetPrimaryPartCFrame() is a good way to move a whole model easily.

  • Global Moderator

    [Tip Added]

    Instead of using Color3.new(r/255,g/255,b/255), use Color3.fromRGB(r,g,b) to use actual RGB values!


  • @eryn No, don't use rendedstepped for animations. Use heartbeat or stepped, it runs at the games frame rate but is more efficient.

    Render stepped will prevent the frame from rendering and other code from running, in other words, render stepped should only be used for camera things.

    Heartbeat runs on another thread while the frame is rendering, making it much more efficient. Zeuxcg himself (technical director at ROBLOX) was the one who explained this.

    This image should help
    alt text


  • [Tip Added]

    My tip:
    :connect, :disconnect and :wait are deprecated ! Use :Connect, :Disconnect and :Wait instead !


  • Take your time to do something correctly. Don't rush!

    Do your best to complete something on your own before asking others for help!

    Try something new everyday! You will learn something.


  • The script output can help you find out what's going wrong. Use the View tab and click Output.

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.