[Help] Criminal Blips filtering out Police job

I’am having trouble with making some blips invisible to the police job.

The error is:

Error resuming coroutine: client/main.lua:22: attempt to index a nil value (field 'job')
stack traceback:
        client/main.lua:22: in function <client/main.lua:21>

The offending code is:

ESX 			    			= nil
local PlayerData 				= {}

Citizen.CreateThread(function()
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end
end)

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
  PlayerData = xPlayer
end)

RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
  PlayerData.job = job
end)

Citizen.CreateThread(function()
  if PlayerData.job.name == 'police' then -- errors here trying to filter out cops :c
		Citizen.Wait(0)
  else
	for i=1, #Config.Map, 1 do
		esxmap_blip = AddBlipForCoord(Config.Map[i].x, Config.Map[i].y, Config.Map[i].z)
		SetBlipSprite (esxmap_blip, Config.Map[i].id)
		SetBlipScale  (esxmap_blip, 0.9)
		SetBlipDisplay(esxmap_blip, 4)
		SetBlipColour (esxmap_blip, Config.Map[i].color)
		SetBlipAsShortRange(esxmap_blip, true)

		BeginTextCommandSetBlipName("STRING")
		AddTextComponentString(Config.Map[i].name)
		EndTextCommandSetBlipName(esxmap_blip)
	  end
	end
end)

I tried to use this topic that Cheleber helped another user in with a similar piece of code:
Help Article referenced

Thanks for your help.

Try to debug it.

Take out the if statement and print(PlayerData.job.name) when you are a policeman. See what it prints.

Where is your Config table coming from?

My config table is coming from a file named config.lua in the root directory of the resource. (ex. resources/mapping/config.lua)

Config = {}

Config.Map = {
  {name="Yacht",color=15, id=410, x=-2045.800, y=-1031.200, z=11.900},
  {name="Coke Picking",color=4, id=501, x=2448.92, y=-1836.80, z=51.95},
  {name="Coke Processing",color=4, id=475, x=-458.13, y=-2278.61, z=7.51},
  {name="Coke Resell",color=4, id=434, x=-1756.19, y=427.31, z=126.68},
  {name="Meth Pickup",color=4, id=501, x=1525.29, y=1710.02, z=109.01},
  {name="Meth Processing",color=4, id=499, x=-1001.41, y=4848.01, z=274.01},
  {name="Meth Resell",color=4, id=434, x=-63.59, y=-1224.07, z=27.77},
  {name="Weed Picking",color=2, id=496, x=1609.125, y=6663.59, z=20.96},
  {name="Weed Processing",color=2, id=514, x=91.06, y=3750.03, z=39.77},
  {name="Weed Dropoff",color=2, id=434, x=-54.24, y=-1443.36, z=31.06},
  {name="Opium Pickup",color=7, id=501, x=1971.26, y=3823.17,  z=32.36},
  {name="Opium Processing",color=7, id=514, x=971.86,y=-2157.61, z=28.47},
  {name="Opium Dropoff",color=7, id=434, x=2331.08, y=2570.22, z=46.68}
}

Everything works fine as this

Citizen.CreateThread(function()
	
	for i=1, #Config.Map, 1 do
		
		local blip = AddBlipForCoord(Config.Map[i].x, Config.Map[i].y, Config.Map[i].z)
		SetBlipSprite (blip, Config.Map[i].id)
		SetBlipDisplay(blip, 4)
		SetBlipColour (blip, Config.Map[i].color)
		SetBlipAsShortRange(blip, true)

		BeginTextCommandSetBlipName("STRING")
		AddTextComponentString(Config.Map[i].name)
		EndTextCommandSetBlipName(blip)
	end

end)

Will get the results of the suggestion print(PlayerData.job.name) in a moment.

[EDIT]
When i print it to [F8] console in game it prints police

Also tried

Citizen.CreateThread(function()
  if PlayerData.job.name ~= 'police' then 
		for i=1, #Config.Map, 1 do
		esxmap_blip = AddBlipForCoord(Config.Map[i].x, Config.Map[i].y, Config.Map[i].z)
		SetBlipSprite (esxmap_blip, Config.Map[i].id)
		SetBlipScale  (esxmap_blip, 0.9)
		SetBlipDisplay(esxmap_blip, 4)
		SetBlipColour (esxmap_blip, Config.Map[i].color)
		SetBlipAsShortRange(esxmap_blip, true)

		BeginTextCommandSetBlipName("STRING")
		AddTextComponentString(Config.Map[i].name)
		EndTextCommandSetBlipName(esxmap_blip)
	  end
	end
end)

But it doesn’t work either…

since police is a string, try "police" (not a LUA guy). Other than that I don’t know. The code looks fine

1 Like

I hadnt thought of that, will try when I get home from work.

[EDIT]
still no luck with that change :c

Please ask in the original resource topic. This way we can prevent the forum from getting cluttered with small questions about x resources.

Also, the topic will serve as a central place for answers, so questions that have been answered will not be asked over and over again.

Thank you for your understanding! :mascot: