MySQL SELECTing fails even though I've used it before perfectly


This is my code

AddEventHandler('esx_parkingjob:ticketCurrentCar', function(currentCar)
	Citizen.Trace("Ticket Created")
	MySQL.Async.fetchAll('SELECT * FROM owned_vehicles', {}, function(veh) -- Fails here
      			local vehCount = 0
      			for i=1, #veh, 1 do
      				local vehicle = veh[i].vehicle
      				if string.find(vehicle, currentCar) then
      					local xPlayer = ESX.GetPlayerFromIdentifier(veh[i].owner)
      					TriggerServerEvent('esx_billing:sendBill', xPlayer.source, 'society_parking', _U('parking'), 150)
						TriggerClientEvent('esx:showNotification', source, "Ticket written for plate: "..currentCar)
						TriggerClientEvent('esx:showNotification', xPlayer.source, "You've been given a parking ticket.")
      					vehCount = vehCount + 1
      			if vehCount == #veh then
      				TriggerClientEvent('esx:showNotification', source, "Ticket written for plate: "..currentCar)
      				TriggerEvent('esx_society:depositMoney', 'society_parking', 150)

My issue is that this creates an error with MySQL callback. Saying: “InvokeNative: execution failed: Argument at index 1 was null.” And then a bunch of other stuff, finishing saying my SELECT was causing an error. I have no idea what’s creating this error since I’ve done this exact section of code in another resource and it works fine.


I had the same issue, you can’t use the “source” argument inside a MySQL callback function to trigger an Event.

Just do local src = source before your MySQL calback and replace “source” by “src” in your TriggerClientEvent()