AddEventHandler('fishing:CheckInv', function()
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.identifier
local executed_query = MySQL:executeQuery("SELECT * FROM user_fish WHERE identifier = '@username'",{['@username'] = player})
local result = MySQL:getResults(executed_query, {'fish_status'})
if (result) then
i = 0
for _ in pairs(result) do
i = i + 1
end
end
local inv = i
inv = tonumber(inv)
print(inv)
end)
TriggerClientEvent("fishing:startFishing", source, inv)
end)
now, to test if this counter works I made it print the amount on console… and it works, it always prints out the right amount from the db.
now, in the client something like this (to test if it passes the value)
Your inv variable is not in the same scope as TriggerClientEvent(“fishing:startFishing”, source, inv) the TriggerClientEvent function can’t see a variable inv in her scope so she pass a nil value. Maybe if you remove the local before the inv. ref : LUA Scope Tutorial
Quick tips to count the number of row of a SQL statement you can use the COUNT keyword it should return the number of row and it’s a more efficient query
SELECT COUNT(*) FROM user_fish WHERE identifier = '@username'
ref : MySQL counting rows
In your client code you will maybe face the same problem as local inv is not specified in the same block. By the way you should rename the following that’s not clear. Hard to read code is hard to debug and it’s not easy to help.