Roblox error tracking installation

  1. Install the Roblox SDK

    Required

    PostHog is available for Roblox through Wally 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
    [dependencies]
    PostHog = "posthog/posthog-roblox@0.1.0"

    You can also download the latest posthog-roblox.rbxm from the releases page 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. Configure PostHog

    Required

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

    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 page in PostHog.

  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
    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. Configure error tracking options

    Optional

    OptionTypeDefaultDescription
    captureErrorsbooleantrueEnables automatic exception capture.
    errorDebounceSecondsnumber1Minimum seconds between automatic server error captures.

    To disable automatic exception capture:

    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 tab.

    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
    error("Automatic test exception from Roblox")

Community questions

Was this page useful?

Questions about this page? or post a community question.