Jump to content

"Bad argument #1 to "pairs" (table expected, got boolean)"


Recommended Posts

Hello, people! Forgive me if I did something bad/wrong, but, I am following tutorials to make scripts.

So.. as u read, in the title, I have this problem "Bad argument #1 to "pairs"(table expected, got boolean)" (line 28); and the other problem : dbPoll failed, near "FROM" : syntax error.(line 26)

function createVehicleForPlayer(player, command, model)
    local db = exports.db:getConnection()
    local x, y, z = getElementPosition(player)
 y = y + 5
 dbExec(db, "INSERT INTO vehicles(model, x, y, z) VALUES(?, ?, ?, ?)", model, x, y, z)
 local vehicleObject = createVehicle(model, x, y, z)
 dbQuery(function (queryHandle)
     local results = dbPoll(queryHandle, 0)
  local vehicles = results[1]
  setElementData(vehicleObject, "id", vehicle.id)
 end, db, "SELECT id FROM vehicles ORDER BY id DESC LIMIT 1")
addCommandHandler("veh", createVehicleForPlayer, false, false)

function loadAllVehicles(queryHandle)
    local results = dbPoll(queryHandle, 0)
 for index, vehicle in pairs(results) do
     local vehicleObject = createVehicle(vehicle.model, vehicle.x, vehicle.y, vehicle.z)
  setElementData(vehicleObject, "id", vehicle.id)
addEventHandler("onResourceStart", resourceRoot, function()
    local db = exports.db:getConnection()
 dbQuery(loadAllVehicles, db, "SELECT + FROM vehicles")
addEventHandler("onResourceStop", resourceRoot, function()
    local db = exports.db:getConnection()
    local vehicles = getElementsByType("vehicle")
 for index, vehicle in pairs(vehicles) do
     local id = getElementData(vehicle, "id")
  local x, y, z = getElementPosition(vehicle)
  dbExec(db, "UPDATE vehicles SET x=?, y=?, z=? WHERE id = ?", x, y, z, id)


Edited by Marshell
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...