0

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
Muto
  • 1
  • 3

1 Answers1

0

you can do like this :

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

    local xPlayer = ESX.GetPlayerData();

    if xPlayer.job.name == "police" then

        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
    else
        print("Vous n'avez pas le bon metier");
    end

end)

Dont use your first line of your script, because is just use during the script load. For efficiency, use it only when you need on a function and before a for or while.

Alex
  • 77
  • 1
  • 1
  • 7
  • Can you provide some more explanation on what does your code do? – Mr.SwiftOak Jun 09 '22 at 07:05
  • Yes, i can. I have only add an IF condition on xPlayer.job.name for test if local player is Police or not, and my fiorst added line is the loading of information about the local player provided by ESX framework. i know that he use ESX Framework by his first line – Alex Jun 09 '22 at 09:20