GeneratePlate Attempt to Index Nul Value

I’m using an older script and need some help if possible.

I’ve got almost everything ironed out except this error.

The snippet below is what is inserted into qb-vehicles.
When a player wins a car this is executed. I’m really not sure how to fix it but it seems like a simple fix for someone with a bit of knowledge. I’m unemployed and poor as dirt, I simply can’t afford to pay for a $40 script for the wheel alone, that’s just bonkers. help me ObiWan Kenobi, you’re my only hope! xoxoxo

-- Win car at luckywheel
RegisterNetEvent('qb-vehicleshop:server:luckywheelWin', function(data, carname)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
	local PlayerData = Player.PlayerData
	local vehicle = data
	local showCar = carname
	
	
    local plate = GeneratePlate()
    MySQL.Async.insert('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, state, garage) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', {
        PlayerData.license,
        PlayerData.citizenid,
        carname,
        GetHashKey(vehicle),
        '{}',
        plate,
        1,
		'casinogarage'
    })
    TriggerClientEvent('qb-vehicleshop:client:winLuckyWheelVehicle', src, vehicle, plate)
    TriggerClientEvent('QBCore:Notify', src, 'Congratulations! Your vehicle can be claimed at the valet near the entrance.', 'success')
end)

The function GeneratePlate() likely doesnt exist in the file. Add this to the file above the event that calls it:

local function GeneratePlate()
    local plate = QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(2)
    local result = MySQL.scalar.await('SELECT plate FROM player_vehicles WHERE plate = ?', { plate })
    if result then
        return GeneratePlate()
    else
        return plate:upper()
    end
end

Found the solution, it was my fault. Must post the above snippet between these two sections.
– Send customer for test drive
Snippet HERE
– Make a finance payment

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