Skip to main content

attempt to index a nil value

❌ Error

attempt to index a nil value (field 'xyz')

📍 Context

Occurs when you try to access a property or table key that is nil. This often happens:

  • When a variable was never initialized.
  • When a database query returns nothing.
  • When a network callback does not return expected data.

✅ Solution

  • Ensure the variable exists before indexing: if myTable ~= nil and myTable.key ~= nil then ... end
  • Verify that callbacks or database fetches return valid values.
  • Initialize tables and default values when creating objects.

ℹ️ Additional Information

  • Can occur both clientside and serverside.