I have a FiveM script on the server side. The script fails to set xPlayer when I connect, when I reload the script once connected to the server everything works as expected.
RegisterServerEvent("eventScript:Ping", function()
local _source = source
Citizen.Wait(3000)
print('Source: '.._source)
local xPlayer = ESX.GetPlayerFromId(_source)
print('xPlayer : '..ESX.GetPlayerFromId(_source))
if not gameInfo.PlayerTeams[_source] then
gameInfo.PlayerTeams[_source] = {
["Team"] = xPlayer.job.name == 'army' and team2 or team1,
["Position"] = GetEntityCoords(GetPlayerPed(_source)),
["IsConnected"] = true
}
end
end)