Skip to content

attempt to index a nil value (local 'input') while canceling dialog box #2

@MG-Alpha

Description

@MG-Alpha
RegisterNetEvent('vhs-stores:open')
AddEventHandler('vhs-stores:open', function(name, config, data, hasItems)
    if hasItems then
        local menuOptions = {}
        for item, data in pairs(data.items) do
            table.insert(menuOptions, { 
                title = ItemLabel(item) .. ' - $' .. data.price, 
                description = 'Stock Available - (' .. data.amount .. 'x)', 
                icon = InventoryImagePath .. item .. ".png", 
                args = { price = data.price, item = item, amount = data.amount },
                onSelect = function()
                    local input = lib.inputDialog('Purchase ' .. ItemLabel(item), { 
                        {type = 'number', description = 'Amount to purchase', icon = 'hashtag', min = 1, max = data.amount, required = true, default = 1} -- Set default value to 1
                    })
                    
                    -- Check if input is nil (canceled) before proceeding
                    if input == nil then
                        --print('Input canceled or closed by user.')
                        return -- Stop further execution
                    end

                    -- Proceed only if input is valid and not empty
                    if input[1] then
                        local buy = lib.callback.await('vhs-store:buyItem', false, name, item, data.price, input[1])
                    else
                        print('No valid amount entered.')
                    end
                end,
            })
        end
        lib.registerContext({ id = 'store_'.. name, title = config.menu.title, options = menuOptions })
        lib.showContext('store_'.. name)
    else
        lib.registerContext({ id = 'store_'.. name, title = config.menu.title, options = {{ title = 'No Items Available' }}})
        lib.showContext('store_'.. name)
    end
end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions