'How can I integrate police job to this command?

I couldn't make only "police" jobs can toggle this command with if xPlayer.job.name == "police" then this code but it didn't worked as I planed

local xPlayers = ESX.GetPlayers()

RegisterNetEvent("pepperspray:Togglepepperspray")
AddEventHandler("pepperspray:Togglepepperspray", function()

    if not holdingpepperspray then
        RequestModel(GetHashKey(peppersprayModel))
        while not HasModelLoaded(GetHashKey(peppersprayModel)) do
            Citizen.Wait(100)
        end

        RequestAnimDict(animDict)
        while not HasAnimDictLoaded(animDict) do
            Citizen.Wait(100)
        end
    end


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source