Having problem sending vars from server side to client.
server
RegisterServerEvent('menu:characters')
AddEventHandler('menu:characters', function(callback)
getCharacters(source, function(data)
first = data.firstname
last = data.lastname
end)
end)
client
RegisterNUICallback('NUICharacters', function(data)
TriggerServerEvent('menu:characters'', data)
SetNuiFocus(true, true)
local bt = first --- Character 1(variable first from server side) ---
SendNUIMessage({
type = "charSelection",
char1 = bt
})
end)
You got this code backwards, You should use TriggerClientEvent to pass data to the client. And adding a event handler on the clientside.
I tried it all the way around but it just returns null. Can you give me any example where u pass a variable from server to client?
Server
TriggerClientEvent('event', -1, 'Hello World!')
Client
RegisterNetEvent('event')
AddEventHandler('event', function(str)
print('Server saids: ' .. str)
end)
Now the server will send an event to all the clients with the data “Hello World!”. If you want a specific client, pass the client source id instead of -1.