Displaying notification message sender name

I am trying to display the username of the user that sent a notification.

RegisterNetEvent('DisplayNFC')
AddEventHandler('DisplayNFC',function(nfcID, inputText)
	local nfc = nfcIdArray(nfcID) 
        local localPlayerId = PlayerId()
        local lpi = GetPlayerServerId(localPlayerId)

	SetNotificationTextEntry('STRING');
	AddTextComponentString(inputText);
	SetNotificationMessage(nfc.pic1, nfc.pic2, true, 4, nfc.sender, lpi);
	DrawNotification(false, true);
end)

It returns the ID of the first person that sends a notification. How can I reset the value or what other code can I use to make this work?

What do you mean? Each time this event is run, it will be run “fresh” unless the values are being stores outside of this event, which it doesn’t look like they are.

Don’t understand what else you need. Are you looking for the get player name native?

No, I don’t store the values. That’s why I am confused that it locks on the initial sender. My goal is that when a user sends a message, the notification message will show the server player name on the subtitle line.

Is nfcID the ID of the person who is sending it?

What does this do? local nfc = nfcIdArray(nfcID)

No, that is the array of the different notifications users can call server side. That all works, it’s just that I can’t find a suiting manner to get the sender’s username and display it. Maybe my thinking is wrong, since I am trying to get the username client side and send it with the message.

You can use this to get a player name from the ID https://runtime.fivem.net/doc/reference.html#_0x406b4b20

You could send the name along, but this able to be abused (never trust the client). Your best option would be to send the event to the server, get the name from the source ID, then send to who it needs to go to.

I’m a bit confused by the code you posted. That doesn’t trigger any server events. It would just show the notification on the sender’s screen. I assume it’s just for testing right now, or…?

For now it is just testing and seeing how I can get this to work. I have been working with this: https://wiki.fivem.net/wiki/GetPlayerName so far and that why I am confused on why

GetPlayerName(source)

doesn’t work when I use that in

SetNotificationMessage(nfc.pic1, nfc.pic2, true, 4, nfc.sender, GetPlayerName(source));

Do I need to get that server side to make it work and put it in a parameter of what am I missing? Like I said, it displays the name of just the first person that sends a message but all message send after that one will still display the username of the first sender.

I’m still a little lost as to how the code snippet you posted is integrated with all of this. That native (GetPlayerName) is also a server-side one.

This would be a proper flow for what you are trying to do, I believe:
-> Sender client triggers a server event sending whatever info is needed
-> Server receives event, gets sender’s name, passes along to who it needs to go to
-> Whoever received event and displays the message.