EN · $ USD
Survival and Sandbox Servers

How to Fix Lua Errors on a GMod Server

7 min read Updated: OyunBulut technical team

In short

To fix a Lua error on a GMod server, start by reading the [ERROR] line in the console: the file path shows which addon caused it, the line number shows where, and the message shows why. If the path isn't clear, disable half of your addons at a time to find the culprit. Check for conflicting file paths, missing dependencies and a corrupt Workshop cache, then restart the server.

In this guide
  1. How to read a Lua error message
  2. The most common Lua errors and what they mean
  3. Finding the broken addon: step by step
  4. Conflicting addons
  5. Clearing corrupt Workshop content
  6. Quick checks from the console
  7. Debugging code you wrote or edited
  8. Keeping errors from coming back
  9. Lua error or lack of resources?
  10. Next step: keep going with a clean server

In Garry's Mod, a Lua error means an addon's or gamemode's Lua code hit something unexpected while running and stopped. Most of the time it comes from a bad line in a single addon, a missing dependency, or two addons overwriting each other's files. The good news: GMod error messages tell you exactly which file and which line the error happened on. This guide shows you how to read the error line, find the problem addon fast and fix the most common error types.

How to read a Lua error message

A typical error in the server console looks like this:

[ERROR] addons/ornek_hud/lua/autorun/server/sv_hud.lua:42: attempt to index global 'DarkRP' (a nil value)
  1. SendHud - addons/ornek_hud/lua/autorun/server/sv_hud.lua:42
   2. fn - addons/ornek_hud/lua/autorun/server/sv_hud.lua:15
    3. unknown - lua/includes/modules/hook.lua:96

Break these lines down like this:

  • addons/ornek_hud/... The file where the error occurred. The first folder name after addons/ (here ornek_hud) is the addon responsible.
  • :42 The line number that failed.
  • attempt to index global 'DarkRP' (a nil value) The cause: the code is trying to access a variable that doesn't exist.
  • Numbered lines (stack trace) The chain of calls that led to the error. The top line is where the error happened; the lines below show how the code got there.

For Workshop addons, the path may start directly with lua/ instead of addons/; in that case, match the file name and folder structure against the addon's contents on its Workshop page to find the source.

Server-side vs client-side errors

GMod code runs in two separate environments (realms): the server and the client. The server console only shows server-side errors. Errors that pop up on players' screens are client-side and show in the player's own console (the ~ key). When a player reports an error, ask them to send a screenshot of the full error text from their console.

The most common Lua errors and what they mean

Error messageMeaningLikely fix
attempt to index a nil valueAccessing a table or object that doesn't existA required addon or gamemode is missing, or the load order is wrong
attempt to call a nil valueCalling a function that doesn't existThe addon expects a different library version or a removed function
attempt to perform arithmetic on a nil valueDoing math on an empty valueA missing or invalid value in a config file
'end' expected, unexpected symbol nearSyntax errorA missing comma, quote or end in a hand-edited config file
bad argument #1 to 'pairs' (table expected, got nil)A function was passed the wrong type of valueThe expected table was never created; config or database data is missing
Couldn't include fileA file to be included couldn't be foundThe addon is incompletely installed or the file name is wrong
stack overflowA function call stuck in an infinite loopTwo addons override the same function and redirect it to each other

Syntax errors show up especially after a config file is edited by hand. In Lua, forgetting a comma between table entries or deleting the closing quote of a string stops the entire addon from loading.

Finding the broken addon: step by step

  1. Reproduce the error. Restart the server and read the console from the top. The first error at startup is usually the root cause; later errors are side effects of it.
  2. Identify the addon from the file path. If the path clearly points to an addon folder, focus on that addon.
  3. Check dependencies. The addon's description lists the libraries or gamemode it needs (e.g. DarkRP, ULib). A missing dependency most often produces an index a nil value error.
  4. If the path isn't clear, use the split-in-half method. Move half of your addons outside the addons folder (e.g. to addons_kapali) and start the server. If the error goes away, the culprit is in the half you moved; if it stays, it's in the half that's still there. Splitting the group in two each round gets you down to a single addon in a few tries.
  5. Update or remove the problem addon. Install the latest version from the developer's page and check the changelog and comments; people with the same error have often posted the fix.

Back up your addons and data folders before you start splitting. We cover backups in the panel in our guide to scheduling automatic backups.

Conflicting addons

GMod merges all addons into a single virtual file system. If two different addons contain a file with the same relative path (for example, both have lua/autorun/client/cl_hud.lua), one replaces the other and the overwritten addon breaks. To detect conflicts:

# Linux: lists files with the same relative path in the addons folder
cd garrysmod/addons
find . -type f -path '*/lua/*' | cut -d/ -f3- | sort | uniq -d

Every path in the output is a file that exists in at least two addons. To fix it, remove one of them, or give file names a unique prefix in addons you develop yourself.

Other common types of conflict:

  • Two admin mods at once: ULX together with SAM or FAdmin active at the same time. Decide which to use with our ULX vs SAM comparison and remove the other.
  • Two addons doing the same job: Two HUDs, two scoreboards or two damage systems modify the same hooks and global variables.
  • Gamemode version mismatch: When DarkRP is updated, old darkrpmodification files or outdated DarkRP addons can throw errors.

Clearing corrupt Workshop content

An addon downloaded from the Workshop may be partially downloaded or corrupted in the cache. In that case, errors show up in odd places that have nothing to do with the code. Here's what to do:

  1. Stop the server.
  2. Delete the server's Workshop cache (usually the Workshop files under garrysmod/cache).
  3. Remove items from your collection that you no longer use or that their author has taken down.
  4. Start the server; the content will be downloaded again.

For managing collections, see our guide to adding a Workshop collection.

Quick checks from the console

You can use the lua_run command in the server console to check whether a variable exists:

lua_run print(DarkRP)
lua_run print(ULib)
lua_run PrintTable(engine.GetAddons())

If the first two commands return nil, that gamemode or library isn't loaded. The third command lists the Workshop addons the server has mounted. Because lua_run runs code on the server with full privileges, it should only be used from the server console and by people you trust.

Debugging code you wrote or edited

If the error is in your own addon or a config file you edited, these techniques speed things up:

  1. Go to the line and print your variables. Add print(), or PrintTable() for tables, right before the failing line to see whether the variable really holds the value you expect.
  2. Add nil checks. In code that depends on another addon, check whether that addon is loaded: a line like if not DarkRP then return end keeps the error from cascading when the dependency is missing.
  3. Think about load order. Files in lua/autorun can run before the gamemode has fully loaded. Move code that accesses gamemode tables into hook.Add("Initialize", ...) or the gamemode's own load hooks.
  4. Check syntax separately. After editing a long config file, running it through a Lua syntax checker catches missing commas or end errors without restarting the server.

Keeping errors from coming back

  • Test new addons on a separate test server before adding them to the live server.
  • Add addons one at a time; if you add ten at once, it's much harder to find which one is causing trouble.
  • Make a copy of config files before editing them.
  • Avoid leaked addons downloaded from unknown sites; they carry both error and backdoor risks.
  • After updates, always read the startup console from top to bottom.

Lua error or lack of resources?

Some symptoms look like Lua errors but are actually caused by a lack of resources: frequent server crashes, freezing on map change, or tick drops under heavy addon load. For servers with lots of addons, a large Workshop collection and a big player base, the OB-GMOD-4 Garry's Mod server with 12 GB RAM leaves comfortable headroom during testing and debugging.

Next step: keep going with a clean server

Once you've found the problem addon, the most lasting fix is to trim your addon list and keep the server organized. OyunBulut's Garry's Mod server plans include file management and console access through the web panel; moving addon folders, reading the console and restarting the server take just a few clicks in your browser. For a community running a big addon set, check out the OB-GMOD-4 plan, and if you get stuck, open a support ticket with our Turkish-speaking support team.

Frequently asked questions

What does 'attempt to index a nil value' mean in GMod?

It means the code is trying to access a table or object that doesn't exist. Usually a library or gamemode the addon needs isn't installed, or the load order is wrong.

How do I tell which addon is causing the error?

In the error line's file path, the folder name after addons/ is the addon responsible. If the path is unclear, disable half of your addons and test to narrow down the culprit.

Players see errors but the server console shows none. Why?

The error the player sees is client-side and only shows in the player's own console. You need to ask the player for the full error text from their console.

Why did my server start throwing errors after a Workshop addon update?

The update may have changed a function another addon uses or added a new dependency. Read the changelog and, if needed, update the related addons together.

Can a Lua error crash the server?

Most Lua errors only stop the function involved, and the server keeps running. However, errors that repeat every tick or a stack overflow can seriously hurt performance and indirectly lead to a crash.

For this guide

Recommended plans

With 12 GB RAM for big addon sets and large Workshop collections, plus file and console access from the web panel, OB-GMOD-4 makes debugging and addon management easier.

OB-GMOD-4

Recommended

12 GB RAM

$9.24/mo

+VAT

  • Processor4 CPU
  • Disk60 GB NVMe
  • LocationIstanbul
  • DDoS Protection
  • Automatic Setup
  • Web Panel
  • 7/24 Support

4 GB RAM

$3.54/mo

+VAT

  • Processor4 CPU
  • Disk30 GB NVMe
  • LocationIstanbul
  • DDoS Protection
  • Automatic Setup
  • Web Panel
  • 7/24 Support

6 GB RAM

$5.31/mo

+VAT

  • Processor4 CPU
  • Disk35 GB NVMe
  • LocationIstanbul
  • DDoS Protection
  • Automatic Setup
  • Web Panel
  • 7/24 Support

Garry’s Mod — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.