I need help to fix this code, Can someone say why isnt this working?

84 Views Asked by At

Im trying to add pictured menu ,but it gives me error.Error, .lua

function loadPlayerInventory()
    TBCore.Functions.TriggerServerCallback('tb-inventory:server:getPlayerInventory', function(data)
        items = 
        inventory = data.inventory
        weapons = data.weapons
        local weight = 0
        

        if inventory ~= nil then
            for k, v in pairs(inventory) do
                table.insert(items, inventory[k])
                weight = weight + (inventory[k].amount * inventory[k].weight)
            end
1

There are 1 best solutions below

0
Piglet On
items = 

should give you an error "unexpected symbol near = So you should not even get to that point that your callback is called.

You forgot to assign a value to items. Your code suggests that it should be a table.

The error in the screenshot is caused by indexing data, a local nil value.

inventory = data.inventory

This is because your callback is called but no parameter data is given. Find out why or make sure you don't index it if it is nil.

Something like

if data then
  inventory = data.inventory
end

or

inventory = data and data.inventory

for example