Error local xplayer

so im getting this error in two scripts that use the same code to check for police, both seem to work fine

function CountCops()

local xPlayers = ESX.GetPlayers()

CopsConnected = 0

for i=1, #xPlayers, 1 do
	local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
	if xPlayer.job.name == 'police' then
		CopsConnected = CopsConnected + 1
	end
end

SetTimeout(120 * 1000, CountCops)

end

image
any help please?

I don’t use esx, but there’s a couple of things you can do to test this:

  1. Print the value (add a line that says print(ESX.GetPlayers()))
  2. Print the TYPE of value. (example: print(type(ESX.GetPlayers()))
  3. Figure out where that number is supposed to pull from
  4. Change what it does so that the value returned is what you’re expecting

Also, is this a client script or a server script?