Attempt to index a nil value (local 'xPlayer')

I’m getting this error

image

This is the server.lua

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

ESX.RegisterServerCallback('censored:fatture', function(source, cb)
	local xPlayer = ESX.GetPlayerFromId(source)
	MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)
		local bills = {}
		for i = 1, #result do
			bills[#bills + 1] = {
				id = result[i].id,
				label = result[i].label,
				amount = result[i].amount
			}
		end
		cb(bills)
	end)
end)

Does anybody know how to fix this?

Try remove “source” from
ESX.RegisterServerCallback('censored:fatture', function(source, cb)
Make it
ESX.RegisterServerCallback('censored:fatture', function(cb)

Try this too by adding

ESX.RegisterServerCallback('censored:fatture', function(source, cb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)

still giving me the same error

Give me 2 min to join on my test server i will send you the fix !

Ok, thank you.

Well, for me this works !

ESX.RegisterServerCallback('censored:fatture', function(source, cb)
    local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
	MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)
		local bills = {}
       if result ~= nil then         
		for i = 1, #result do
			bills[#bills + 1] = {
				id = result[i].id,
				label = result[i].label,
				amount = result[i].amount
			}
		end
		cb(bills)
       else
        cb(false)
       end
	end)
end)

Check on client the Callback

I have no idea why this doesn’t work for me.

This is the error I get

[  script:censored] SCRIPT ERROR: @censored/server.lua:9: attempt to index a nil value (local 'xPlayer')
[  script:censored] > TriggerServerCallback (@es_extended/server/functions.lua:160)
[  script:censored] > handler (@es_extended/server/common.lua:81)
[  script:es_extended] SCRIPT ERROR: error object is not a string
[  script:es_extended] (nil stack trace)SCRIPT ERROR: @censored/server.lua:9: attempt to index a nil value (local 'xPlayer')

My updated server.lua is

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

ESX.RegisterServerCallback('censored:fatture', function(source, cb)
    local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
	MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', {
		['@identifier'] = xPlayer.identifier
	}, function(result)
		local bills = {}
       if result ~= nil then         
		for i = 1, #result do
			bills[#bills + 1] = {
				id = result[i].id,
				label = result[i].label,
				amount = result[i].amount
			}
		end
		cb(bills)
       else
        cb(false)
       end
	end)
end)

In my server.lua line 9 means

['@identifier'] = xPlayer.identifier

These are my client callbacks

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(5)
		ESX.TriggerServerCallback('censored:fatture', function(bills)
			PersonalMenu.BillData = bills
			ESX.PlayerData = ESX.GetPlayerData()
		end)
	end
end)
		local action = data.current.value
		if action == 'paga' then
			ESX.TriggerServerCallback('esx_billing:payBill', function()
				ESX.TriggerServerCallback('censored:fatture', function(bills) PersonalMenu.BillData = bills end)
			end, PersonalMenu.BillData[i].id)
		end

Do you have any ideas?

Maybe i wrong, but i think is something from your ESX version, what version you have ? !
Try go to es_extended/server/functions.lua on line 158 or 160 you must find something like this

ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
	if ESX.ServerCallbacks[name] then
		ESX.ServerCallbacks[name](source, cb, ...)
	else
		print(('[es_extended] [^3WARNING^7] Server callback "%s" does not exist. Make sure that the server sided file really is loading, an error in that file might cause it to not load.'):format(name))
	end
end

Check if is like this! if not replace it…

i already have this in my es extended, i’m running the latest artifact from fivem.

which esx version are you using :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.