THE ORB
Starting the studio

TypeError: Cannot read properties of undefined

A script expected some information and got nothing. It is the same class of problem as the most common Lua error.

groupsThat feature stops workingcodeNeeds a developer

Do this first

Note which script it names; the fix is in that script's code.

bug_reportPaste your whole console instead

What it means

JavaScript's version of "attempt to index a nil value". Something was accessed on a value that is undefined or null. The message names the property, which tells you which access failed but not which value was missing.

What causes it

Ordered by how often it is the answer.

  1. 1

    A player object that does not exist

    A server script looking up a player who has disconnected.

  2. 2

    An await that was forgotten

    const rows = db.query(...) without await gives a Promise, and reading a field off it is undefined.

  3. 3

    A destructure of a missing object

    const { id } = payload when payload never arrived.

  4. 4

    An event payload the client did not send

    Same class of bug as the Lua version, on the other runtime.

  5. 5

    An export from a resource that is not started

    exports['x'].y where the export object is undefined.

How to tell which one is yours

console.log(typeof thing, thing)

directly above the failing line. In FXServer this prints to the server console like any other output.

Where to look

The named line, then the assignment that produced the undefined value.

How to fix it

Use optional chaining and defaults at the boundary:

const player = getPlayer(src)
if (!player) return

const amount = payload?.amount ?? 0
const rows = await db.query('SELECT ...')

Still stuck on your own code?

This page is what this error usually means. Paste your console into Server Fixer and it will rank everything in it and tell you what to do first, and if you would rather not touch it, ORBIE can repair the script and hand the resource back ready to drop in.

bug_reportOpen Server Fixer

Errors that travel with this one