In Pursuit of Perfect Code: Multiplayer Script Debugging

Remote Error Monitoring System

Now you’ve done it. You got interested in this “Lua scripting” thing you keep hearing about on our forums and reading about on our blog. You tinkered with it for a while. You even got to the point where you were able to understand enough to make your own online game. You’re like Neo, from the Matrix, crafting virtual realities from little glowy bits of green code. You are invincible. Your game gets super popular. It’s great.

Then the bug reports start to flow in. You get hundreds of private messages a day that all have the same general subject line: “dude your game is broken fixfixfixfix”. You know a little bit about debugging, so you start your level in ROBLOX Studio and run it locally using Test –> Start Server & Test –> Start Player. You have the Output window open, so you can see script errors as they occur. You know that once you see what the error message is, it is typically easy to fix. Reproducing and isolating the bug is most of the work. This time, however, you’re stuck. The bug only happens in multiplayer mode, on the production site, What do you do?

Remote Debugging to the Rescue


Tyler Mullen, of the the ROBLOX Content Team, has developed a new tool that will collect information from your running games. It can save and track:

  • Server uptime
  • Player visit stats: joins, leaves, average playtime, and number of unique visitors
  • Lua statistics: number of errors, warnings, and number of scripts running
  • Lua stack traces for recorded errors (this is the exciting part)

The best part of this tool is that it will record data even when you are not in your game. If you have a bug in your map that only happens every 10 hours, you can let your game run all day, then take a peek and see what’s going on.

How to Install the Tool

First, grab a free copy of this model. Open ROBLOX Studio and insert it into the Workspace of the place you want to track. Then expand the model in the explorer and find the AdminList StringValue. Add your username to the list. You can have as many users as you want – these are players that will see the Place Console when they visit the tracked place (careful: these users can shut your place down). Publish your map to ROBLOX. The next time you join the map, you’ll get the Place Console.


  • There is currently no way to minimize the Place Console; this is a very early version of this particular tool. Eventually, the functionality of this tool will be built into ROBLOX. For now, the window can’t be minimized, but it’s draggable.
  • The scripts used here are digitally signed by ROBLOX–if you edit any of the scripts, the tool will stop working, as it depends on several high-privilege functions to work properly.

How to Use the Remote Error Logging System to Debug Scripts

This is the cool part. The tool you just installed will capture erroneous scripts, along with a stack trace. How is this useful to you? When a place is “broken” online, 95% of the time it’s broken because one of the game scripts in it has stopped running. This happens when scripts encounter an error, unless the erroneous block of code is wrapping in a pcall, which would be an interesting topic for another article altogether. The stack trace can show you exactly what your scripts were doing before they errored out.


As an experiment, I added the remote error logging system to Sword Fight on the Heights IV. I thought that the code in this level was relatively simple, and for the most part the level runs without problems, so I didn’t expect to see many errors. I had quite a few, it turns out.

An error in Sword Fight on the Heights IV breaks the part of the code that causes players to drop all the items that they are carrying when they get bloxxed. Here is the stack trace:

Workspace.LeaderboardV3, line 78 – global dropWeapons

Workspace.LeaderboardV3, line 125 – global onHumanoidDied

Workspace.LeaderboardV3, line 136.

In the tool this is all compressed into one line. The topmost line (or the first one, if you’re reading left to right in the tool), is the line number where the error happened. The remaining lines are functions that were called prior to the error occurring. This can be extremely helpful in diagnosing complex situations, as the error may have happened in shared code that has numerous callers. The actual error, in this case, was:

Torso is not a valid member of Model

If you see an error like this, get psyched–these types of errors are easiest to fix because they are commonly caused by code assuming that an object will exist (and when it doesn’t, it causes the error). I opened my script in ROBLOX Studio, navigated to line 78 and noticed a very unsafe-looking reference to humanoid.Parent.Torso…


This code is unsafe because it assumes that a part called “Torso” will be found in the humanoid’s parent. If this part is missing, this line of code will error out.

In my case, I estimate the condition is being triggered when the character falls off the edge of the world. By the time my code is getting called, this character’s Torso has been removed from the Workspace. If this happens, it doesn’t matter if he drops his weapons since no one is going to be able to pick them up. So the fix is very easy–I simply test that the Torso exists before I bother trying to drop his weapons.


What Next?

Writing perfect code is hard. Actually, there is strong evidence that it might be theoretically impossible, so don’t feel bad if your script has bugs in it. I got lucky with this particular bug–most bugs you find will probably be bad references–similar to the one I had. But it’s possible to have bugs that don’t crash scripts, which makes them much harder to find. You can get logic bugs (where the code isn’t doing what you think it is), or race conditions (when two scripts are halted waiting for each other to finish, or otherwise interfere with each other because they are both manipulating the same objects). In these cases, it’s best to remove variables and simplify your program until you can diagnose the problem accurately. Fixing all the common bugs that happen frequently in your levels can help find rare bugs that don’t happen all that often.

For instance, I know that the teleport gates in Sword Fight on the Heights occasionally breaks. It doesn’t happen very often, and I didn’t see it happen in any of my instrumented levels. However, with this tool, I’m going to go back and fix all my trivial bugs, even if they hardly ever happen. Then when I load up Sword Fight on the Heights and see a stack trace, I’ll know I’ve struck gold.

About John Shedletsky

ROBLOX Creative Director @Shedletsky on Twitter

75 thoughts on “In Pursuit of Perfect Code: Multiplayer Script Debugging

  1. discreetairsoft

    New to scripting and I needed debuging for my scripts because I’m not a very good scripter. This is just what I need!

  2. Gusmanak

    Most helpful thing I have ever seen. I really need this BIG TIME. I finally have time to fix Apocalypse Rising!

  3. TheSandwich

    I made one of these like, a year and a half ago. But this has a nicer GUI and is more user friendly. Taken.

  4. V6a6m6pyro

    Good to see something like this has appeared.

    I’m assuming this will lead to a built-in administration system for all places? Even then, it will always have its limits and people will constantly be adding their own personal touches, but a step forward is always a good thing.

  5. 99Nickster

    I don’t have enough fingers or toes to count the number of times I could have used something like this, thanks!

  6. Zhoutai189

    Very nice. Thanks for the tips and the interesting link on how programs can never be perfectly coded.

  7. cardgamechampion

    This is great! Now if we want we can debug coding in-game. I have a question though, not really about this, but about SFOTHO: Why does it load 24k Parts these days? For many people (not sure if it’s everyone or not), it says Bricks: 24000 something when it loads the bricks and connectors. Did you add invisble parts to it to test ROBLOX’s maximum brick count?

  8. classytitanic

    Good job guys! I’m happy to be a player in Roblox. I’m glad to see how far Roblox has gotten! Keep up the great work!

  9. As8D

    Uwsum! I tried taking the model a few months ago, sadly it was only for admins, so the event somewhere wouldn’t run xP

    —> Until now, I’ve found errors in-game using ypcall & a loop checking whatever ypcall returns. Now, that’s going to be implemented in every script, which is somewhat of a pain for my scripting hand.

    (Note: Will the debug tool run before a place is loaded? I’d like to check what makes my place SHUT DOWN LAIK CAKE! when someone enter >_>)

  10. Sethalonian

    I am glad they used their admin powers to open some functions that will help us. I hope they make updates on it soon. XD

  11. Tallthedude

    This is amazing, it’ll make place building/scripting much easier, especially for noobs at scripting! :D

  12. Dactor123

    Awesome! This is going to help loads of people including me! It’s going to make debugging so much easier!

  13. agr0n

    Huh that is really cool! One thing though the way that you added the “signed” by you guys to the code so it can’t be modified is interesting. Could you give that to the players so that we can sign our own stuff preventing other people from changing it. Like if you release a freemodel script, but you don’t want it to be changed?

    1. Coenmcj

      Indeed it would, but since when does roblox give us things WE (As the customers and users) What we need and want?

    2. hiccster

      @agr0on – You hit the nail on the head, that would be a fantastic option to have, in-game and as free models.

    3. Ajedi32

      Signing doesn’t work quite the way you seem to think it does. The code needs to be signed in this case because it calls some functions that can’t be called by user-created scripts. (For security reasons.) That’s why the script doesn’t run if you change it.

  14. Scooby8snacks

    I say, good job.

    Although, would you, my lads, be able to create a script that will allow certain players to shutdown a server?

    That would benefit us users world wide.

    1. Guest 2012 (21st of Dec.)

      You can just make one of those yourself, using a server crasher instance.
      Like“ManualSurfaceJointInstance”) sort of thing

  15. NeedlessRocker1

    Haha, nice work! Im not a good or not even a intermediate scripter, but I know the professional scripters will love it.

  16. Luckymaxer

    Also, what I do is include enough checks just to ensure that what I want is possible, otherwise skip the specific process and go back to it some other time. – This is a nice way to prevent bugging.

  17. SkateBored

    >ROBLOX Update breaks zombie spawns in Apocalypse Rising
    >Gusmanak tries to fix it.
    >Shedletsky makes a tool that helps Gusmanak fix it.
    >All is good in the land of craters and frogs.

  18. wow25

    Oh, my goodness, this abosulutely revolutionized roblox game building, i could not be more ga;d that you made this!! Thank you soo much!

  19. Ianliu12345

    I have a good game, I really only want to update my GUIs, but no one visits :3

    Still, this seems like a cool tool.

Comments are closed.