ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
ESXserver

ESX.GetPlayerFromId

ESX server documentation with a FiveM Lua example.

Summary

Returns the server-side xPlayer object for a given source. The authoritative ESX player object for money, jobs, and inventory.

Returns

table (xPlayer) — with functions like addMoney, setJob, addInventoryItem.

Parameters

sourcenumberThe player's server ID.

Example

ESX = exports['es_extended']:getSharedObject()

RegisterNetEvent('myscript:pay', function()
  local src = source
  local xPlayer = ESX.GetPlayerFromId(src)
  if not xPlayer then return end
  xPlayer.addMoney(500)
end)

Common pitfalls

  • Guard against nil: if not xPlayer then return end. A missing check here is the #1 cause of 'attempt to index a nil value (local xPlayer)'.
  • Do all money/job/item logic here on the server, never on the client.

Related functions

Related guides

Managing jobs on your server?

Viper Multi-Job lets players hold several jobs and switch between them with grade, salary and duty handled — QBCore, QBox and ESX, validated server-side.

See Viper Multi-Job →