shared
GetPlayerName
FiveM shared native documentation with a Lua example.
Summary
Returns the display name of a player by their ID. On the server, pass the source/player ID.
Returns
string — the player's name.
Parameters
playerIdnumberThe player/server ID.Example
-- SERVER
RegisterCommand('whoami', function(source)
print('Player: ' .. GetPlayerName(source))
end, false)Common pitfalls
- Player names are user-controlled — don't trust them for identity; use identifiers/license for that.
- On the client, player indices differ from server IDs.
Related natives
Related guides
FiveM scripts done right
Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.
Browse Scripts →