Hello, I’ve tried everything I could for displaying the SOURCE players name. It either comes back invalid or chooses someone random on the server…

Here’s the code.

server.lua

RegisterServerEvent("SyncTweets")
AddEventHandler('SyncTweets', function(inputText)
TriggerClientEvent('DisplayTweet', -1, inputText)
end)


AddEventHandler('chatMessage', function(from, name, message)
	if message == "/t" then
		CancelEvent()
		TriggerClientEvent("TweetAlert", from)
	end
end)

client.lua

local name = GetPlayerName(source)

RegisterNetEvent("TweetAlert")
AddEventHandler("TweetAlert",function(name)
		DisplayOnscreenKeyboard(false, "FMMC_KEY_TIP8", "", "", "", "", "", 99)
		local input = true
		Citizen.CreateThread(function()
		while input do
		if input == true then
		HideHudAndRadarThisFrame()
		if UpdateOnscreenKeyboard() == 3 then
		input = false
		elseif UpdateOnscreenKeyboard() == 1 then
		local inputText = GetOnscreenKeyboardResult()
		if string.len(inputText) > 0 then
		TriggerServerEvent('SyncTweets', inputText)
		input = false
		else
			DisplayOnscreenKeyboard(false, "FMMC_KEY_TIP8", "", "", "", "", "", 20)
		end
		elseif UpdateOnscreenKeyboard() == 2 then
		input = false
		end
		end
		 Citizen.Wait(0)
		 end
			
end)
end)

RegisterNetEvent('DisplayTweet')
AddEventHandler('DisplayTweet',function(inputText)

SetNotificationTextEntry("STRING");
AddTextComponentString(inputText);
SetNotificationMessage("CHAR_PLANESITE", "CHAR_PLANESITE", true, 1, "New Tweet from", "~b~@"..name);
DrawNotification(false, true);

end)

Because:
GetPlayerName(ID) exists server-sided and client-sided but takes different IDs as parameters.

On the server side you can use the source (ServerID), but on client side you have to use the ClientID.

The ServerID & ClientID of a player don’t always have to be the same…

So, when you use “from” it is the ServerID, which is only used server-sided and causes this problem you have:

To fix this, there are two options. First get the name on the server side and give it over to the client or convert the ServerID to the ClientID with this Native: GetPlayerFromServerId(ServerID) (But if I recall right, it wasn’t working for me, so better use option one)

Option One:
server.lua

RegisterServerEvent("SyncTweets")
AddEventHandler('SyncTweets', function(inputText)
TriggerClientEvent('DisplayTweet', -1, inputText)
end)


AddEventHandler('chatMessage', function(from, name, message)
	if message == "/t" then
		CancelEvent()
		TriggerClientEvent("TweetAlert", GetPlayerName(from))
	end
end)

Appreciate the effort, but option one didn’t work for me.

What didn’t work? Tell me more, so I Can help you.

I just completely rewrote it a different way, and it had the same output so all is good.