Stellar AI

Blog

QBCore Nil Value Error: Index Nil Fixes

Use this prompt in Stellar AI:

“My QBCore script says attempt to index a nil value. Here is the exact error line, server console, fxmanifest, config table, start order and the code around the line. Diagnose the nil source first, then patch only what is needed.”

Identify the nil object first

A nil value error is not a random QBCore problem. It is a precise clue: the script tried to read a property from something that does not exist at that moment. Look at the error line and find the value immediately before the dot, colon or bracket access. If the line says Player.PlayerData.job.name, the nil object could be Player, PlayerData or job. Your job is to identify which one is missing before changing the logic.

Do not start by rewriting the whole resource. Copy the full error, the file path and the few lines above the reported line. Lua stack traces often point to the line where the failure becomes visible, while the real cause may be a value that was never loaded, a callback that returned nothing or a config key that was misspelled earlier.

Check QBCore export timing

If the core object itself is nil, confirm that qb-core starts before the custom resource and that the export pattern matches your installed QBCore version. Older scripts sometimes use a different core-object pattern from the framework currently installed on the server. If the script was copied from another server, do not assume the framework version is the same.

local QBCore = exports['qb-core']:GetCoreObject()
if not QBCore then
  print('QBCore is not loaded for this resource')
  return
end

That kind of temporary guard is not a final fix, but it confirms whether the script can see the framework. Once the cause is known, clean the debug output and keep only proper validation.

Validate player data before indexing into it

Player data can be unavailable if the player is not fully loaded, has disconnected or the code is running on the wrong side. On the server, use the framework’s player lookup and check the result before reading nested values. On the client, wait for the correct player-loaded event before expecting job, gang or metadata values to exist. Timing problems are especially common when a script runs immediately on resource start rather than after login.

If the script is tied to a menu, target zone, inventory item or command, print the player source and the lookup result at the start of the handler. If the lookup fails, handle the failed lookup and stop gracefully. Never keep indexing deeper into a missing player object.

Compare config names against real server data

Config tables cause many nil value errors. A job key, item name, grade number, stash id, zone name or locale key can be misspelled in one file and used correctly everywhere else. The script then tries to index into a config entry that does not exist. Search for the exact key across config, client and server files. Confirm that the job names match the jobs registered in QBCore and that the item names match the inventory resource.

When a resource has nested config, check each level. For example, Config.Locations.police.armory can fail because Locations is missing, police is missing or armory is missing. Do not assume the final key is the problem until you check each parent table.

Protect callbacks and database results

A callback can return nil when a database row does not exist, a player lacks permission, a query failed or a dependency resource is not ready. Treat every callback result as optional until you validate it. If the result is missing, return a clear error notification or server log instead of indexing into it. For database-backed resources, confirm the table and column names match the SQL installed on this server.

local row = result and result[1]
if not row then
  print('No database row found for this lookup')
  return
end

That pattern keeps the server from cascading into deeper errors. It also gives you better evidence for the next fix.

Use one small failing path

If a large resource fails in several places, isolate one action: opening a menu, using an item, starting duty or saving a vehicle. Test that path with one player and one role. Once you know which object becomes nil, the fix is usually small. The answer may be dependency order, wrong config key, missing SQL, outdated export or code that runs before player data is ready.

What to paste into Stellar AI

  • The exact nil value error and file line.
  • The surrounding code block.
  • Your fxmanifest and resource start order.
  • The relevant config table.
  • The player action that triggered the error.
  • Whether it happens server-side, client-side or both.

Ask for diagnosis first. A good AI patch should name the nil object, explain why it is nil and make the smallest safe change. Avoid patches that simply hide the error without fixing the missing data, dependency or timing problem.

Related guides

Want it fixed for you? The £99 Priority Script Fix is a one-off fix for a FiveM or Roblox script. Memberships start at £8 a month on the plans page.

Related tools: QBCore script generator · Fix a FiveM Lua error · all script generators