SCRIPT ERROR: @d-phone0.5/server/server.lua:64: attempt to index a nil value (global 'ESX')

SCRIPT ERROR: @d-phone0.5/server/server.lua:64: attempt to index a nil value (global ‘ESX’)

I use the “d-phone” script for my server and get this error everytime i press f1 in game. It shows “you have to have a phone to open it” and i dont know what to do. I copied the sql in my database, tried to create an item manually and give it to me, but i dont know the “name” of it exaktly.

Maybe its an easy solution, maybe not. Help would be nice!

I have never worked with d-phone sounds like it’s attempting to call an item that it cannot locate can you send us a code snippet from line 60 to 70?

1 Like

RegisterServerEvent(‘d-phone:server:checkphone’)

AddEventHandler(‘d-phone:server:checkphone’, function(source)

local _source = source

local xPlayer = ESX.GetPlayerFromId(_source)

local item = xPlayer.getInventoryItem("phone")

if item.count >= 1 then

    TriggerClientEvent("d-phone:client:hasphone", _source)

end

end)

1 Like

Even if a have an Item called “phone” in my inventory, its not working. Do you know how to change the code to work?

do you have ESX = nil in your server script followed by

– the line need to be alon like these –

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

–not like these–

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
end)

on top off all script

2 Likes

Here you got the first 25 Lines of Server.lua. Should be fine, i think, like you said


ESX = nil

local backgroundurl

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

MySQL.ready(function()

    Wait(1000)

    MySQL.Async.fetchAll('SELECT * FROM jobs ', {}, function(result)

        for _,v in pairs(result) do

            MySQL.Async.fetchAll("SELECT * FROM `phone_messages` WHERE `receiver` = @receiver OR `sender` = @receiver" , {["@receiver"] = v.label}, function(messages)

                if messages[1] ~= nil then

                    MySQL.Async.execute("DELETE FROM `phone_messages` WHERE `receiver` = @receiver" , {

                        ["@receiver"] = v.label,

                    })

                    MySQL.Async.execute("DELETE FROM `phone_messages` WHERE `sender` = @receiver" , {

                        ["@receiver"] = v.label,

                    })

                end

            end)

        end

    end)

end)

Are you trying to start the phone before ESX in your server.cfg?

1 Like

Im new at Fivem Developement and dump. that was the error. Thanks Man!

Solution: You have to start the Phone after esx, but before the ambulancejobs, etc, that you can send dispatched.

1 Like

Now the Item works! But i got a new Error

That was already in console:

Access denied for command add_principal.
es_extended: invalid item “d-phone” ignored!
Access denied for command add_principal.
es_extended: invalid item “d-phone” ignored!

thats the new error: (the phone works, but i cant take it away and the apps do not work correktly)

SCRIPT ERROR in reference call: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

Add this to your server.cfg:

add_ace resource.essentialmode command.add_principal allow

You need to add d-phone to your items table.

1 Like

Tanks, the errors are away now. But theres one last left and most of the Phone included Apps seems not to work

SCRIPT ERROR in reference call: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

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