[Solved] GetPlayer...() In client.lua

Being new to FiveM scripting and Lua, I’ve been confused on how to use things like GetPlayerName() and GetPlayerServerId() functions in the client script. I have my main machine and another one which I have a second account running on, and everytime I run something like GetPlayerName() on either machine it returns the name of the account on my main one. The same applies to GetPlayerServerId(). I’m unsure as to why these aren’t returning the local player’s names and id’s, unless there is something I’m missing?

You need to specify source.

How would I go about getting the source without relying on the server?

Would I have to use a GetPlayers() function or is there a more efficient route?

src = source

That still needs the server though.

In order to do it on the client GetPlayerName(PlayerId()) should work.


Yea I’ve tried doing this but it only returns **Invalid** :confused:

This seems to work out anyways. Thanks @Scott_UK , somehow I must’ve missed that in the docs.

1 Like

Hey @Scott_UK. If I typed a command in chat, How would I make it so that the person that typed the command shows on a ui. I am making a priority script. and wanting to show who the person currently doing priority is. I have it all setup, Just need help with adding the Player name native.

How can I get a player’s source other than me ?
Can I find other player’s source using their serverId? if I can do, which method should I use?

Why would you assign a new variable to a global variable…

Because if you want to use source in a async callback or after the return event you need to store it as a variable.

iirc GetPlayerName() ain’t async :man_shrugging:

Some functions don’t have source by default so it’s good to grab it. It’s more specific to certain senarioes. Here just used so people are not like “what’s source” lmao

Hey @FAXES, I know you might just ignore this message/reply. But if you do read it…

I am setting up a Priority Status script. It works perfectly fine, But I tried to add in GetPlayername() | But it keeps messing up. I tried it in client, But it only showed the person at the top of the playerlist, and I also tried it in server, But then it kept showing the person that first toggled the start priority when the resource was (re)started. This is the code I have right now. (please dont get angry because i am asking this in this thread. it is still related to the same native :slight_smile: )


AddEventHandler('UpdatePriority', function(newispriority, playername)
    ispriority = newispriority
	playername = playername


AddEventHandler('isPriority', function()
	playername = GetPlayerName(-1)
	ispriority = true
	TriggerClientEvent('UpdatePriority', -1, ispriority)

Hope you can help out with this.

-1 specifies all players. Not a single player.

What do I do to show the player that triggers the Event?


ok cool, Thanks