[HELP] mysql key lock system

Hey, so i’m pretty new to lua and i’m not sure about how for loops work. I’m trying to make a key system for vehicles in my server, which reset at each reboot. Here’s my code server side:

Citizen.CreateThread(function()
	MySQL.Async.fetchAll('SELECT * FROM owned_vehicles', {}, function(result)
		print(json.encode(result))

		for k, v in pairs(result) do
			local plate = v.plate
			MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE plate = @plate', { ['@plate'] = plate }, function(newresult)
				print(json.encode(newresult[1].owner))
				local newnewkeys = {
					newresult[1].owner
				}
				local newkeys = json.encode(newnewkeys)
				MySQL.Async.execute('UPDATE owned_vehicles SET cles = @newkeys WHERE plate = @plate', {
					['@newkeys'] = newkeys,
					['@plate'] = plate
				})
			end)
			
		end
	
	end)

end)

This part works all well and is meant to reset the “key” column in the mysql table to the car’s owner’s identifier only, at each reboot.

I have a server callback to check if the person has the keys to the car or not:

ESX.RegisterServerCallback('carlock:hasKeys', function(source, cb, plate)
	local xPlayer = ESX.GetPlayerFromId(source)
	local identifier = xPlayer.identifier
	



	MySQL.Async.fetchAll('SELECT cles FROM owned_vehicles WHERE plate = @plate', {
		['@plate'] = plate
	}, function(result)

		local cles = result


		for k, v in pairs(cles) do
			print(cles[k])

			if identifier == cles[k] then
				cb(true)
				print("callback true")
			else
				cb(false)
				print("callback false")
			end

		end

	end)

end)

For some reason print(cles[k]) prints “table: 0x7fed520c8a00”. Not sure how to fix it

hi, see here.

print(cles[k])

change to

print(cles)

Hey,

Indeed that would work but i’d like to have “cles” as a list with the identifier of everyone who has the keys of that car. I’m not sure how to set cles as a list (i tried with the local newnewkeys = {} but i’m not sure that works?)