This script will be correct?

ESX = nil
Citizen.CreateThread(function()
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end
end)
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0) 
        if ESX then
            local player = PlayerId()
            -- Verifica si el jugador es policía
            if ESX.GetPlayerData().job and ESX.GetPlayerData().job.name == 'police' then
                -- Desactiva el nivel de búsqueda para el jugador policía
                SetPlayerWantedLevel(player, 0, false)
                SetPlayerWantedLevelNow(player, false)
            end
        end
    end
end)

I want to use a wanted level for all servers but doesn’t affect cop

Hi, have you tried this to see if it works? Or does it not work and you’re asking why? As the code seems like it would work by looking at it.

In theory it should work , I have not tested it . but I wonder if it is correct for the way I am going to create with the script. It happens that I want the wanted level to be set only for the police . Let the other people shoot and have their wanted level activated. but when the police shoot the wanted level it is not activated…. It’s that I’ve messed with this script for fun because by command I can make it easier but I wanted to create that everyone who was a policejob didn’t have wanted level h, the others did. For example, he is collecting drugs… the wanted level is activated for those boys and when the police npc arrive more, the police job arrives, they can shoot the police job without the police movs shooting at them

I’m not too familiar with ESX, but to start with, I’d start with not calling PlayerId() every tick for performance purposes. Does ESX not provide a function that returns local Player Id? If so, I’d use that assuming it’s not just directly calling the native itself.