# Roblox error tracking installation - Docs

1.  1

    ## Install the Roblox SDK

    Required

    PostHog is available for Roblox through [Wally](https://wally.run) or as a model file you import in Studio.

    Via Wally, add the dependency to your `wally.toml`, run `wally install`, and map the package into `ReplicatedStorage`:

    toml

    PostHog AI

    ```toml
    [dependencies]
    PostHog = "posthog/posthog-roblox@0.1.0"
    ```

    You can also download the latest `posthog-roblox.rbxm` from the [releases page](https://github.com/PostHog/posthog-roblox/releases) and insert it into `ReplicatedStorage` in Studio. Either way you should end up with `ReplicatedStorage > PostHog`.

    Make sure HTTP requests are enabled for your experience: **Game Settings > Security > Allow HTTP Requests**.

2.  2

    ## Configure PostHog

    Required

    Initialize PostHog once from a server `Script` (for example in `ServerScriptService`), keeping error capture enabled:

    lua

    PostHog AI

    ```lua
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local PostHog = require(ReplicatedStorage:WaitForChild("PostHog"))
    PostHog:Init({
        apiKey = "<ph_project_token>",
        host = "https://us.i.posthog.com",
        captureErrors = true,
        errorDebounceSeconds = 1,
    })
    ```

    You can find your project token and instance address in the [project settings](https://app.posthog.com/project/settings) page in PostHog.

3.  3

    ## Capture exceptions

    Required

    The Roblox SDK captures exceptions automatically by default. On the server it listens to `ScriptContext.Error`; requiring the module from a `LocalScript` captures unhandled client errors and relays them to the server.

    Captured events include the error message, the stack trace when available, and SDK metadata.

    For handled errors, call `CaptureException` manually with a subject, message, and optional trace and properties:

    lua

    PostHog AI

    ```lua
    local ok, err = pcall(function()
        saveGame(player)
    end)
    if not ok then
        PostHog:CaptureException(player, err, debug.traceback(), {
            flow = "save_game",
        })
    end
    ```

    **Identified users**

    Server events are already attributed to the player you pass as the subject (by their `UserId`), so exceptions are linked to known users in PostHog automatically.

4.  4

    ## Configure error tracking options

    Optional

    | Option | Type | Default | Description |
    | --- | --- | --- | --- |
    | captureErrors | boolean | true | Enables automatic exception capture. |
    | errorDebounceSeconds | number | 1 | Minimum seconds between automatic server error captures. |

    To disable automatic exception capture:

    lua

    PostHog AI

    ```lua
    PostHog:Init({
        apiKey = "<ph_project_token>",
        captureErrors = false,
    })
    ```

5.  ## Verify error tracking

    Recommended

    Trigger a test exception and confirm it appears in the [Error tracking](https://app.posthog.com/error_tracking) tab.

    lua

    PostHog AI

    ```lua
    PostHog:CaptureException(nil, "Test exception from Roblox", debug.traceback())
    PostHog:Flush()
    ```

    To test automatic capture, raise an unhandled error from a server `Script`:

    lua

    PostHog AI

    ```lua
    error("Automatic test exception from Roblox")
    ```

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better