how to get player source object using server id

hello guys i was wondering how can i get player object from his server id in this code

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(5000)
		maxClientNum = GetConvarInt("sv_maxClients", 0)
		if not isProcess then
			isProcess = true
			playerList = {}
			local players = ESX.GetPlayers()
			for i=1, #players do 
				local xPlayer = ESX.GetPlayerFromId(players[i])
		
				local playersId = xPlayer.source
				local roles = exports.Badger_Discord_API:GetDiscordRoles(xPlayer.source)
				local donator = false
                if roles ~= false then 
                    for k, v in pairs (roles) do
                        if xPlayer.getGroup() == "--[[Discord Role Id]]" then 
                            donator = true
                            break
                        end
                    end
                    if donator == false then
                        table.insert(
                            playerList,
                            {
                                id = xPlayer.source,
                                nickname = xPlayer.getName(),
                                job = xPlayer.job.name,
                                class = "white"
                            }
                        )

                    else
                        table.insert(
                            playerList,
                            {
                                id = xPlayer.source,
                                nickname = xPlayer.getName(),
                                job = xPlayer.job.name,
                                class = "rainbow"

                            }
                        )
                    end
                else
                    table.insert(
                        playerList,
                        {
                            id = xPlayer.source,
                            nickname = xPlayer.getName(),
                            job = xPlayer.job.name,
                            class = "white"
                        }
                    )
                end
                    
			end
			TriggerClientEvent('vrp_rw_userlistC.updatePlayerList', -1, playerList, maxClientNum)
			isProcess = false
		end
	end
end)

this function exports.Badger_Discord_API:GetDiscordRoles requires player source and this function ESX.GetPlayers() returns all active player server ids so i hope any help arrive soon

First of all, why do you define playersId as xPlayer.source and then instead of using playersId you use xPlayer.source in the GetDiscordRoles function.
Second, you don’t even need to define playersId as the xPlayer.source, because players[i] is already the player’s id, so you could just define playersId as players[i].
Basically you could just use exports.Badger_Discord_API:GetDiscordRoles(players[i]) and answering your question the player server id is called a source in server events called by the client, in this case the function requires a player server id.

first thank u for ur help
second i have tried this but it gave me error i will tyri to use GetPlayers() the native function instead of this ESX.GetPlayers()
i belive that ESX.GetPlayers using the old way to retrive the players