-1

so im gettin this error so i know theres something i probably gotta fix here but i have no idea how .thanks

SCRIPT ERROR: @gcphone/server/server.lua:205: attempt to index a nil value (local 'items')

CODE FROM LINE 205

ESX.RegisterServerCallback('crew-phone:phone-check', function(source, cb)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return; end
    for k, v in pairs(Config.Phones) do
        local items = xPlayer.getInventoryItem(v)
        if items.count > 0 then
            cb(v)
            return
        end
    end
    cb(nil)
end)

ESX.RegisterServerCallback('crew-phone:item-check', function(source, cb, data)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return; end
    local items = xPlayer.getInventoryItem(data)
    cb(items.count)
end)
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64

1 Answers1

0

This error tells you that items is a nil value and Lua complains about it because you try to index it as in items.count. That doesn't make sense if items is nil It's like referring to a book page of a non-existant book.

local items is nil because xPlayer.getInventoryItem(data) returned nil

Check wether the local script provides a string for data when triggering the server event and if xPlayer actually has an item like that.

Also check your RegisterServerCallback. The function you define there is the callback. Why is there another callback in that function argument? I think you're confusing things and probably should refer to the manual again.

https://esx-framework.github.io/es_extended/server/functions/registerservercallback/

Piglet
  • 27,501
  • 3
  • 20
  • 43