Retrieve player character name

Hey, i want to get the ESX Character Names of the nearby players instead of the steam names for esx_inventoryhud, how would i go about doing this? because in this code(client side):
` RegisterNUICallback(
“GetNearPlayers”,
function(data, cb)
local playerPed = PlayerPedId()
local players, nearbyPlayer = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)
local foundPlayers = false
local elements = {}

    for i = 1, #players, 1 do
        if players[i] ~= PlayerId() then
            foundPlayers = true

            table.insert(
                elements,
                {
                    label = GetPlayerName(players[i]),
                    player = GetPlayerServerId(players[i]),
                }
            )
        end
    end

    if not foundPlayers then
        exports.pNotify:SendNotification(
            {
                text = _U("players_nearby"),
                type = "error",
                timeout = 3000,
                layout = "bottomCenter",
                queue = "inventoryhud"
            }
        )
    else
        SendNUIMessage(
            {
                action = "nearPlayers",
                foundAny = foundPlayers,
                players = elements,
                item = data.item
            }
        )
    end

    cb("ok")
end

)`
it gets the Steam name with label = GetPlayerName(players[i])
but to get the Character Name i somehow have to pass the players to the Server, and do e.g xPlayer.getName() for each one and return them back to the client right? how does this work

u can use TriggerServerEvent to get the name from there if the name can be one fetched from there bec I am not so expert in esx so u can use servercallbackevent too in order to get his name

Yes i tried but i have problems passing the players to the server and then passing the names back to the client

u can simply use ESX.TriggerServerCallBack its easy to use as callback

I’ve got it to work now using TriggerServerEvent and TriggerClientEvent

yup both TriggerServerEvent and TriggerClientEvent works but ESX.TriggerServerCallback is just small code and more optimized but if its work then gl <3

I also tried with ESX.TriggerServerCallback but that i could not get to work… but thanks!