FiveM: 'attempt to call a nil value (field ...)' – Fix
The error
SCRIPT ERROR: @my_resource/server.lua:12: attempt to call a nil value (field 'GetPlayerByCitizenId')
What it means
Lua looked up a function by name and found nil, then tried to call it. The name in brackets is the missing function. Common causes:
- The function was renamed or removed in your framework version (QBCore and ESX have both renamed functions between releases).
- You are calling a server-only function from a client file, or the other way round.
- A typo or wrong capitalisation: Lua names are case-sensitive.
- The file that defines the function is not listed in
fxmanifest.lua, or loads after the file that calls it.
The fix
-- 1. Check the function exists before calling it while you debug
local QBCore = exports['qb-core']:GetCoreObject()
print(type(QBCore.Functions.GetPlayerByCitizenId)) -- 'function' or 'nil'
-- 2. Make sure fxmanifest loads shared files first
shared_scripts { 'config.lua', 'shared/*.lua' }
server_scripts { 'server/*.lua' }
client_scripts { 'client/*.lua' }If it prints nil, search your framework's source for the current function name and update the call. Check the line number in the error to see which file and side (client or server) is failing.
Related errors
- qbcore getcoreobject nil
- fivem couldnt load resource fxmanifest
- fivem oxmysql no such export
- esx getsharedobject deprecated
Related tools: FiveM script generator · Fix a FiveM Lua error · all script generators