ESX EUP UI error (NativeUI) attempt to index a nil valuie (global 'ESX')

Hi, when calling the /eup command to use the NativeUI I get the below error

The code it is referencing is below

lines 697 - 703

RegisterCommand('eup', function()
    if ESX.PlayerData.job and ESX.PlayerData.job.name == 'police' then
    mainMenu:Visible(not mainMenu:Visible())
    else
        ESX.ShowNotification("You are not a Police officer")
    end
end, false)

The error happens because you do not have ESX installed.
Strangely enough the version of EUP I installed does not require ESX…

Workaround is pretty easy though: Copy the following piece of code directly in front of the noted command.

PlayerData = {}
PlayerData.job = {}
PlayerData.job.name = 'police'

Same error unfortunately but with the new line numbers

697 - 707

PlayerData = {}
PlayerData.job = {}
PlayerData.job.name = 'police'

RegisterCommand('eup', function()
    if ESX.PlayerData.job and ESX.PlayerData.job.name == 'police' then
    mainMenu:Visible(not mainMenu:Visible())
    else
        ESX.ShowNotification("You are not a Police officer")
    end
end, false)

Or do you mean like this?

RegisterCommand('eup', function()
    PlayerData = {}
    PlayerData.job = {}
    PlayerData.job.name = 'police'
    if ESX.PlayerData.job and ESX.PlayerData.job.name == 'police' then
    mainMenu:Visible(not mainMenu:Visible())
    else
        ESX.ShowNotification("You are not a Police officer")
    end
end, false)

In theory I meant the first option but was too lazy to really check what I wrote :smiley:

As you are not using ESX I think the easiest option will be just scrapping the if-clause:

RegisterCommand('eup', function()
  mainMenu:Visible(not mainMenu:Visible())
end, false)

If that doesn’t work (which would be fairly strange), try putting

ESX = {}
ESX.PlayerData = {}
ESX.PlayerData.job = {}
ESX.PlayerData.job.name = 'police'

in front of the Command.

1 Like

When you say not using ESX I’m a bit confused lol… I am using ESX resources… esx_police, esx_ambulance etc & those jobs all work to assign to players

I went with your 2nd suggestion & it now works, Thanks!