[Help] Data not passing to the server side

Hello. I have a problem with passing my variable to the server side. No idea why it’s becoming nil on the server side, because I always used that method and never had any problems with it :slightly_frowning_face:

client side

RegisterNUICallback("CreateCharacter", function()
    print(characterData.firstname) -- It prints great
    TriggerServerEvent('PonderosaRP:RegisterNewChar', userData.chars, characterData.firstname, characterData.lastname, characterData.gender, characterData.date)
    TriggerServerEvent('PonderosaRP:UpdateCharCount', true)
    SetNuiFocus(false, false)
end)

server side

RegisterServerEvent('PonderosaRP:RegisterNewChar')
AddEventHandler('PonderosaRP:RegisterNewChar', function(id, firstname, lastname, gender, date)
  print(firstname) -- It prints nil now
  local _id = id
  local _source = source
  local license = LicenseIdentifier()
  if id == nil then
    _id = 1
  else
    _id = _id + 1
  end
  MySQL.ready(function ()
    MySQL.Async.execute('INSERT INTO prp_chars (license, charId, firstname, lastname, gender, date, job, rank, money, bank, skin, location, weapons, isDead, hunger, thirst, stamina) VALUES (@license, @charId, @firstname, @lastname, @gender, @date, @job, @rank, @money, @bank, @skin, @location, @weapons, @isDead, @hunger, @thirst, @stamina)',
      {
        ['@license']        = license,
        ['@charId']         = _id,
        ['@firstname']      = firstname,
        ['@lastname']       = lastname,
        ['@gender']         = gender,
        ['@date']           = date,
        ['@job']            = "unemployed",
        ['@rank']           = 0,
        ['@money']          = 0,
        ['@bank']           = 0,
        ['@skin']           = '{}',
        ['@location']       = '{"x":2688.9987792969,"y":-1459.9288330078,"z":46.271617889404}',
        ['@weapons']        = '{}',
        ['@isDead']         = 0,
        ['@hunger']         = 100,
        ['@thirst']         = 100,
        ['@stamina']        = 0
      }
    )
  end)
end)

error message (no idea why it is null)

You’ve got no data here. Is this just a bad copy paste, or have you not defined the variable?

I don’t want any data coming from js. I just want the “click” to trigger all previous data collected already in client side to be sent to server side.

Ah, I see, I assumed that data was from said callback.

See what happens if you pass just characterData to the server, then access it (e.g. print(characterData.name).

I tried that in the beginning. It doesn’t make any difference.This is so weird :thinking:

I remember running into a similar issue a little time ago, and if I recall off the top of my head the issue had to do with the data being reset/changed on the client by the time it was set to the server; maybe have a check around and see if the data is chanaged anywhere on the clinet like in a loop or similar.

Seriously I can’t see anything. And here look please at this example from the same script:
client.lua

RegisterNUICallback("RegisterNickname", function(data)
    userData.name = data.nick
    TriggerServerEvent('PonderosaRP:RegisterNewUser', userData.name)
end)

server.lua

RegisterServerEvent('PonderosaRP:RegisterNewUser')
AddEventHandler('PonderosaRP:RegisterNewUser', function(name)
  local _source = source
  local license = LicenseIdentifier()
  MySQL.ready(function ()
    MySQL.Async.execute('INSERT INTO prp_users (license, name, chars, power, warns, isBanned) VALUES (@license, @name, @chars, @power, @warns, @isBanned)',
      {
        ['@license']      = license,
        ['@name']         = name,
        ['@chars']        = 0,
        ['@power']        = 0,
        ['@warns']        = 0,
        ['@isBanned']     = 0
      }
    )
  end)
end)

And this one is working without any problems. And this is practically 1:1 :confused: Also I have no loops (or threads) in the code yet.