Debugging for beginners!

  • Hey there! My name is Aimarekin and if you're HERE it's because you're new to LUA
    and you want to program the next-generation murder game! (Or whatever)

    Anyway, maybe you noticed that programming is not as easy as writing a word document, and that there could "spawn" some freakin' brain toaster errors. Believe me, you'll freak out lots of times while scripting thanks to these! But, if you want to keep your reputation safe, it will be better if you try to research a bit before asking in scriptinghelpers for help. Now, we're going to learn some "Debugging"! Let's begin!


    • What is debugging?

    Debugging, in computer programming and engineering, is a multistep process that involves identifying a problem, isolating the source of the problem, and then either correcting the problem or determining a way to work around it. The final step of debugging is to test the correction or workaround and make sure it works.

    As a summary, debugging is to find the source of bugs and fix them to prevent users finding glitches in your game. This can be either a long or short progress, depending of the bug you may find. Some may be difficult, others may be just a typo. There are many glitches you will find and you will need to use debugging to solve em'.

    • Sure, but... How do I do that?

    Excellent question!
    How the heck do we do that?
    There isn't a precise way to debug, because it may depend on the bugs we may find. Sometimes we will just need to check for typos... For example here:

    local workspace = gameWorkspace

    Let's check... Oh, of course. i forgot the dot... Here you go.

    local workspace = game.Workspace

    Other times, it won't be that easy...

    But because you're new to this, we won't give any examples.
    Anyway, doesn't care what is your error... Here are the most basic steps for debugging...

    1. Check if the script is disabled
      May seem stupid, but the script the script won't run until it's enabled again... To check if a script is disabled, click the script object and check that the "Disabled" property is set to false. Anyway, making a script disabled can be useful, and can be set to true or false by other running scripts.

    2. Check for typos
      Typos sometimes happen. Check that your script has no typos, like trying to make this script.Parent.Parent.Money.Value and you accidentally added two parents instead of one. Or maybe instead of writing local you wrote locsl. Make sure you check carefully!

    3. Check if your script is localscript or script
      Have in count that a client-side (LocalScript) script runs way different than a server-side (Script) script. Many things like game.Players.LocalPlayer can NOT be obtained in a script because it's running server-side (The server isn't a player!), but it can be obtained by a localscript because the client DOES have a player. Check if your script is client-side or server-side and if you're triying to obtain things that you can't like localplayer in a server-side script. Also check if your game is FE (Filtering Enabled) because FE games behave different than non-FE. For more information, check the ROBLOX Wiki about FE:

    4. Use print() statements
      Did you knew about print ()? Of course you did, sure you executed at least once print ("Hello World!")! But, did you knew that print () is actually used for debugging? For example, you may do something like... print ("The script is running!") at the very beginning of your script to tell yourself in the output that the script is running. Or you may do print ("The function has ended and it returned ".. VALUEGOESHERE) to check in the output values. Cool, isn't it? Or you may do print ("Function 1 running") to check that your function was triggered! And also print ("Function 1 ended, ".. PLAYER .. " was killed") to check if the function ran successfully and check who did it killed. Or you may do print ("Function 1 ended, failed to find humanoid, nobody was killed.") To check that your script went wrong. But, did you knew that there is NOT only print()? You may use too error () and warn ()! Seems great, huh? The error () statement will return an error (Which also breaks the script, it stops it, remind that)! For example, instead of doing print ("Function 1 ended, failed to find humanoid, nobody was killed.") you may do error ("Function 1 ended, failed to find humanoid, nobody was killed.") to show the text red in the output and break the script! Or maybe you could do error ("Error while setting an ID for ".. plr .. ", ".. plr .. " was kicked.") this will break the script too, which means that it will stop any upcoming event.. The warn () statement will print in the output yellow text. For example, in a for i loop you may do: warn ("Loop 1 is running, the i value is ".. i) or... warn ("Tried to get leaderboard stats ".. TimesTried .. " times, ".. MaxTriesCount - TriesTried .. " tries left")! See this is the most large part of all the tutorial, because it's the part where you should make more effort!

    5. Ask for help
      Asking for help is great. As a beginner, you'll need much of this. Help can be provided by anyone, and even if it's better to try things by yourself, asking for help is not always bad. Renember that the most important thing while asking for help is not to fix the glitch, it's to understand the mistakes you've done, integrate them and remember them for your future scripts. And finally, fixing the glitch.

    Hope this tutorial was useful for you to debug your games!
    Have luck in your games!

  • Good tutorial.
    This would be very helpful to me, if i didn't know about debugging.

  • @Void_Frost
    Thanks! First tutorial I made. :D

Log in to reply

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