[HELP] Why is my value from server being passed as nil?

on server I have something like this

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)

RegisterNetEvent('fishing:startFishing')
AddEventHandler("fishing:startFishing", function(inv)
		local inv = inv
		Citizen.CreateThread(function()
		Citizen.Wait(1)

			drawNotificationBoat(inv,0,1,0.5,0.8,0.6,255,255,255,255)
		
		end)
end)

In the game console I get error attempt to concatenate a nil value (upvalue ‘inv’)

I don’t get it why this is not working, can someone help me out? thanks

try [ local inventory = inv ] not sure if you can make them the same name. Pretty sure they must be different.

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.

local inv = inv