Source Changing from number to string

this is my script and print in console ,

And when I do ,

print(“FIRSTSPAWN”)
print(type(source))
print(json.encode(source))
getSkin(player)
print(“FIRSTSPAWN2”)
print(type(source))
print(json.encode(source))

I got ,

FIRSTSPAWN
number
1
GETSKIN
1
[0ms] SELECT * FROM skin WHERE identifier = @username
GETSKIN2
1
FIRSTSPAWN2
string
“”

Thanks

Yes? What did you expect when you encode it. It returns an empty string as it’s invalid json.

I got the same result without json.encode

the source change type :

FIRSTSPAWN
number
1

FIRSTSPAWN2
string

I’m not sure if this is related, but I had a similar situation where source would just randomly change on me. Try doing local source = source at the top of the event. That fixed my problem. Not sure if it would help, but worth a try I guess…

maybe I found the issue the source change just after SQL Request ,

SOURCE
number
1
[0ms] SELECT * FROM skin WHERE identifier = @username
SOURCE
string

Code ::

        print("SOURCE")
	print(type(source))
	print(source)

	 local skin = MySQL.Sync.fetchAll("SELECT * FROM skin WHERE identifier = @username", {['@username'] = player})

	print("SOURCE")
	print(type(source))
	print(source)

local source = source

solve the problem but I have to add it in every Event and function

this is probably an issue with this ‘mysql’ library you’re using that should retain source but doesn’t

yeah I’m using MySQL-Async for FXServer

Yeah… I randomly started having that issue recently. Might as well add it if it works for now… :frowning:

Same here without any mysql querie

AddEventHandler("inventory:add", function(id, item, quantity)
  local InvId, InvType = GetInventoryType(id)
  local inv
  local isAbleToReceive
  if InvType == "personal" then
    TriggerEvent("es:getPlayerFromId", source, function(user)
      inv = user
      isAbleToReceive = user.isAbleToReceive(tonumber(item), quantity)
    end)
  elseif InvType == "car" then
    if car == nil or not(car) then
        CancelEvent()
    end
    TriggerEvent("car:getCarFromPlate", InvId, function(car)
      inv = car
      isAbleToReceive = car.isAbleToReceive(tonumber(item), quantity)
    end)
  elseif InvType == "chest" then
    isAbleToReceive = false -- TODO
  end

  if isAbleToReceive then
    inv.addQuantity(item, quantity) -- à tester sinon IF
    TriggerClientEvent("inventory:change", source, json.decode(inv.sendDatas())) -- HERE
  end
end)

On the “HERE” comment line my source is a string

It’s not mysql. On linux FXServer, if you call a different event/callback, within an event, the souce gets set to nil when the callback is returned. Windows doesn’t seem to be suffering from this. @Briglair is correct, local source = source forces it to persist through. Might not be exactly what OP is running into, but something strange still happening.