> ## Documentation Index
> Fetch the complete documentation index at: https://docs.virusstudio.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Debugging Tips: Fix Lua & Python Script Errors Fast

> Learn to read Lua and Python error messages, understand the most common script errors, and know what to include when submitting a bug fix request.

Errors are a normal part of scripting — even experienced developers spend a significant portion of their time debugging. The good news is that most errors follow recognisable patterns, and once you know what to look for, you can diagnose problems in minutes rather than hours. This guide breaks down the most common Lua and Python errors, shows you what they mean, and explains how to give us everything we need to fix a broken script quickly.

***

## How to Read an Error Message

Every error message contains at least three pieces of useful information:

1. **The error type** — what kind of problem occurred (e.g. `TypeError`, `attempt to index nil`)
2. **The location** — the file name and line number where the error was detected
3. **The message** — a description of what went wrong

Read the location first to find the right line, then read the message to understand why. The line number points to where the problem *surfaced*, which is not always where the *cause* lives — but it is always the right place to start investigating.

***

## Error Reference

<AccordionGroup>
  <Accordion title="Lua Errors" icon="code">
    ### `attempt to index nil value`

    This is the most common Lua error. It means you tried to access a property or call a method on a variable that is `nil` (has no value).

    ```lua theme={null}
    -- Error example
    local player = nil
    print(player.Name) -- Error: attempt to index nil value (global 'player')
    ```

    **What to do:** Check that the variable was actually assigned before you use it. In Roblox, this often happens when `FindFirstChild()` returns `nil` because the object does not exist yet — use `WaitForChild()` instead, or add a `nil` check.

    ```lua theme={null}
    -- Safe pattern
    local player = Players:FindFirstChild("Virus")
    if player then
        print(player.Name) -- Only runs if player exists
    end
    ```

    ***

    ### `attempt to call nil value`

    You tried to call something as a function, but it turned out to be `nil`. This usually means a typo in the function name or a missing `require()`.

    ```lua theme={null}
    -- Error example
    local result = myFunction() -- Error if myFunction was never defined
    ```

    **What to do:** Double-check spelling. If you are calling a method on a module, make sure you `require()`d it and that the function is actually defined in the module's return table.

    ***

    ### `stack overflow`

    A stack overflow means a function called itself (directly or indirectly) so many times that Lua ran out of memory for the call stack. The most common cause is infinite recursion.

    ```lua theme={null}
    -- Error example
    local function countdown(n)
        print(n)
        return countdown(n - 1) -- Never hits a base case!
    end
    countdown(10) -- Error: stack overflow
    ```

    **What to do:** Make sure every recursive function has a clear base case that stops the recursion.

    ```lua theme={null}
    -- Fixed version
    local function countdown(n)
        if n <= 0 then return end -- Base case
        print(n)
        return countdown(n - 1)
    end
    ```

    ***

    ### `expected near '<eof>'` or `expected 'end'`

    These are syntax errors. Lua expected a keyword like `end`, `)`, or `then` but reached the end of the file (or an unexpected token) instead. Every `if`, `for`, `while`, `do`, and `function` block needs a matching `end`.

    ```lua theme={null}
    -- Error example (missing 'end')
    local function greet(name)
        if name then
            print("Hello, " .. name)
        -- Missing 'end' for the if block and for the function
    ```

    **What to do:** Count your `if`/`for`/`function` openings and make sure each one has a corresponding `end`. Most code editors highlight mismatched blocks.
  </Accordion>

  <Accordion title="Python Errors" icon="terminal">
    ### `NameError: name 'x' is not defined`

    You referenced a variable or function that Python cannot find in the current scope. Either it was never defined, it was defined later in the file, or it is in a different scope.

    ```python theme={null}
    # Error example
    print(username)  # NameError: name 'username' is not defined
    ```

    ```text theme={null}
    Traceback (most recent call last):
      File "script.py", line 2, in <module>
        print(username)
    NameError: name 'username' is not defined
    ```

    **What to do:** Make sure the variable is defined *before* the line that uses it. Check for typos — Python is case-sensitive, so `Username` and `username` are different variables.

    ***

    ### `TypeError: unsupported operand type(s)`

    You tried to perform an operation on incompatible types — most often mixing a string and a number.

    ```python theme={null}
    # Error example
    age = "25"
    next_year = age + 1  # TypeError: can only concatenate str (not "int") to str
    ```

    ```text theme={null}
    Traceback (most recent call last):
      File "script.py", line 3, in <module>
        next_year = age + 1
    TypeError: can only concatenate str (not "int") to str
    ```

    **What to do:** Convert types explicitly before operating on them. Use `int()`, `float()`, or `str()` to coerce values.

    ```python theme={null}
    age = "25"
    next_year = int(age) + 1  # Works correctly → 26
    ```

    ***

    ### `IndentationError: unexpected indent`

    Python uses indentation to define code blocks. An `IndentationError` means a line is indented more (or less) than Python expected.

    ```python theme={null}
    # Error example
    def greet(name):
    print("Hello, " + name)  # IndentationError: expected an indented block
    ```

    **What to do:** Make sure the body of every `def`, `if`, `for`, `while`, and `with` block is consistently indented — either always 4 spaces or always one tab, never a mix.

    ```python theme={null}
    def greet(name):
        print("Hello, " + name)  # Correctly indented
    ```

    ***

    ### `FileNotFoundError: [Errno 2] No such file or directory`

    Python could not find the file at the path you provided.

    ```python theme={null}
    with open("data/report.csv", "r") as f:
        content = f.read()
    # FileNotFoundError: [Errno 2] No such file or directory: 'data/report.csv'
    ```

    **What to do:** Double-check the path. Use `os.path.exists()` to verify a file exists before opening it, or use an absolute path to avoid ambiguity about the working directory.
  </Accordion>

  <Accordion title="General Debugging Tips" icon="wrench">
    ### Use Print Statements to Trace Values

    When you are not sure what a variable contains at a given point, print it. Place `print()` calls at key moments — before a function call, inside a loop, or after a condition — to watch values change as the script runs.

    ```lua theme={null}
    -- Lua example
    print("Health before damage:", health)
    health = health - damage
    print("Health after damage:", health)
    ```

    ```python theme={null}
    # Python example
    print(f"Processing file: {filename}")
    print(f"Row count before filter: {len(df)}")
    ```

    ***

    ### Isolate the Problem

    If a long script is failing, comment out sections until the error disappears. The last section you commented out is where the problem lives. Then narrow it down further within that section.

    ***

    ### Check Types Before Using Values

    Many errors happen because a value is a different type than you expected. Print the type to confirm.

    ```lua theme={null}
    print(type(myValue))  -- Lua: prints "string", "number", "table", etc.
    ```

    ```python theme={null}
    print(type(my_value))  # Python: prints <class 'str'>, <class 'int'>, etc.
    ```

    ***

    ### Read the Full Traceback

    Python tracebacks show the entire call chain leading to the error — read them from **bottom to top**. The bottom line is the actual error; the lines above show which function calls led there.

    ***

    ### Roblox: Use the Output and Developer Console

    In Roblox Studio, open the **Output** window (`View → Output`) to see print statements and errors in real time. For client-side errors that do not appear there, press `F9` during a play session to open the **Developer Console** and switch to the **Client** tab.
  </Accordion>
</AccordionGroup>

***

## Submitting a Bug Fix Request

When you ask us to fix a broken script, the more context you provide, the faster we can solve it. Here is exactly what to include:

<Note>
  **Include all of the following in your bug fix request:**

  1. **The full error message** — copy and paste the entire error, including the file name and line number. Screenshots are helpful too.
  2. **The relevant script** — share the complete script, or at minimum the function/section where the error occurs.
  3. **What you expected to happen** — describe the intended behaviour in one or two sentences.
  4. **What actually happened** — describe what the script did instead (wrong output, crash, no output, etc.).
  5. **When it happens** — does the error occur every time, or only under certain conditions? (e.g. "only when the player's inventory is empty")
  6. **What you have already tried** — if you made any changes attempting to fix it, let us know so we do not retrace your steps.
</Note>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Submit a Request" icon="file-code" href="/getting-started/submitting-a-request">
    Ready to hand off a broken script? Submit a bug fix request and we will get it sorted.
  </Card>

  <Card title="Troubleshooting" icon="circle-question" href="/support/troubleshooting">
    Browse common issues and solutions in our troubleshooting reference.
  </Card>
</CardGroup>
