QBCore Frameworkqbcore.netCommunity docs
On this page

1 min read

Fix an attempt to index a nil value

An “attempt to index a nil value” message identifies the file and line where Lua received no table or object. Fix the first error in the log before changing downstream resources.

Evidence to collect

  • Full first stack trace, not only its final line
  • Resource name, deployed commit, and local diff
  • Whether the code runs on client or server
  • Values immediately before the failing access

Diagnostic

For Player.PlayerData.job.name, Lua can fail because Player, PlayerData, job, or name is missing. Log the boundary value without printing tokens or private player data:

local Player = QBCore.Functions.GetPlayer(source)
if not Player then
    print(('missing player object for source %s'):format(source))
    return
end

Common causes are code running before OnPlayerLoaded, an invalid server source, a callback that returned nil, a resource that started before its dependency, or a key that changed between commits. Confirm the current export or callback signature at the deployed source.

Fix and verify

Fix the lifecycle or data contract that produced nil. Add a guard only when absence is an expected state. Reproduce the original flow, reconnect once, restart the affected resource, and confirm the first error does not return.

Rollback

Restore the previous resource commit and configuration. Keep the failing logs and diff so the data contract can be corrected before retrying the update.

Sources

Found an issue in this guide?

Send the page URL, the affected example, and a source or reproduction to the site maintainer. For a server or resource problem, use the support guide.

On this page