RegisterCommand?

So i’ve looked around and i can’t seem to make this command work.

PlayerData = {}

local done = false

ESX = nil

RegisterCommand("duty", function(source, args, rawCommand)

PlayerData = ESX.GetPlayerData()
    while PlayerData.job == nil do
        return
    end
    
    if PlayerData.job and PlayerData.job.name == 'police' then
        exports["rp-radio"]:GivePlayerAccessToFrequencies(1, 2, 3)
    elseif PlayerData.job and PlayerData.job.name == 'ambulance' then
        exports["rp-radio"]:GivePlayerAccessToFrequencies(1, 2, 3)
    elseif PlayerData.job and PlayerData.job.name == 'mechanic' then
        exports["rp-radio"]:GivePlayerAccessToFrequency(3)
    else
        exports["rp-radio"]:RemovePlayerAccessToFrequencies(1, 2, 3)
end, false)

Hello i hope this helps.

RegisterCommand("duty", function()

    sourceXPlayer = ESX.GetPlayerData()

    while sourceXPlayer.job == nil do

        return

    end

    

    if sourceXPlayer.job and sourceXPlayer.job.name == 'police' then

        exports["rp-radio"]:GivePlayerAccessToFrequencies(5, 6, 7, 8, 9, 10, 11)

    elseif sourceXPlayer.job and sourceXPlayer.job.name == 'ambulance' then

        exports["rp-radio"]:GivePlayerAccessToFrequencies(5, 6, 7, 8, 9, 10, 11)

    elseif sourceXPlayer.job and sourceXPlayer.job.name == 'mecano' then

        exports["rp-radio"]:GivePlayerAccessToFrequency(12)

    elseif sourceXPlayer.job and sourceXPlayer.job.name == 'taxi' then

        exports["rp-radio"]:GivePlayerAccessToFrequency(13)

    else

        exports["rp-radio"]:RemovePlayerAccessToFrequencies(5, 6, 7, 8, 9, 10, 11, 12, 13)

    end

end)

You might wanna change the channels and job names

The value of ‘ESX’ is nil and never changes so that would mean ‘sourceXPlayer’ would also be nil thus leading to nothing below the loop working because you’re exiting with ‘return’

I think that this can help you


ESX = nil

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
PlayerData = ESX.GetPlayerData()
end
end)


local done = false

RegisterCommand("duty", function(source, args, rawCommand)
    if PlayerData.job and PlayerData.job.name == 'police' then
        exports["rp-radio"]:GivePlayerAccessToFrequencies(1, 2, 3)
    elseif PlayerData.job and PlayerData.job.name == 'ambulance' then
        exports["rp-radio"]:GivePlayerAccessToFrequencies(1, 2, 3)
    elseif PlayerData.job and PlayerData.job.name == 'mechanic' then
        exports["rp-radio"]:GivePlayerAccessToFrequency(3)
    else
        exports["rp-radio"]:RemovePlayerAccessToFrequencies(1, 2, 3)
end, false) 
1 Like

ESX is still nil though so you’ll be stuck in an infinite loop forever

I did that loop for putting something in, but you can do it without the ESX

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.