Taking out a value off a NetEvent?

Hi, here is my piece of code and i’ll ask my question after:

Server

RegisterServerEvent('getnumberPlate')
AddEventHandler('getnumberPlate', function()
  TriggerEvent('es:getPlayerFromId', source, function(user)
    local player = user.identifier
    local executed_query = MySQL:executeQuery("SELECT * FROM users WHERE identifier = '@username'",{['@username'] = player})
    local result = MySQL:getResults(executed_query, {'numberplate'})
    if(result)then
      for k,v in ipairs(result)do
        print(v.numberplate)
        get_veh_plate = v.numberplate
      end
    end
    TriggerClientEvent('getnumberplateGranted', source, get_veh_plate)
  end)
end)

Client

RegisterNetEvent('getnumberplateGranted')
AddEventHandler('getnumberplateGranted', function(plate)
	local veh_plate_number = plate
end)

So my question is, is it possible to take out the var veh_plate_number and use it elsewhere in the code like in another thread for example ?

Thank you

Okay, so.

If you would like to use veh_plate_number elsewhere in your client files, you need to make the variable global.

To do so, at the top of your client file, you would do

veh_plate_number = 0

Then in your event you can do.

RegisterNetEvent('getnumberplateGranted')
AddEventHandler('getnumberplateGranted', function(plate)
	veh_plate_number = plate
end)

You are now overwriting that variable and you can now access it elsewhere, just make sure to do a check to see if it’s set.

An example would be:

triggerEvent("chatMessage", "Server", {255, 255, 255}, "My number plate is: "...veh_plate_number)

Ohhhh shiet thank you ! :slight_smile:

I tried to do this but after calling the variable outside the net event function it just returns the old value… How could i fix this?