[HELP] Print the players name in chat

Im trying to print

Officer: [Players name] Unracked his rifle
Officer: [Players name] Racked his rifle

I know where to put it back I cant figure it out how get the players name.

-------------------- CARBINE ------------------------------

local carbine = false

RegisterNetEvent("rifle")
AddEventHandler("rifle", function()
	carbine = not carbine
    if carbine then
		GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), 1000, false)
		GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), GetHashKey("COMPONENT_AT_AR_FLSH"))
		GiveWeaponComponentToPed(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), GetHashKey("COMPONENT_AT_SCOPE_MEDIUM"))
		TriggerEvent("chatMessage", "^1Officer:" [The players name] "Unracked his rifle")
    else
        RemoveWeaponFromPed(GetPlayerPed(PlayerId()), GetHashKey("WEAPON_CARBINERIFLE"))
		TriggerEvent("chatMessage", "^1Officer:" [The players name] "Reracked his rifle")
	end
end)

Thanks!

Just one note, this would only print on your client. Not for everyone.

Well sh*t, How uhm…Do I fix that? Lol

U will need also a server.lua.

To get the playername: NetworkPlayerGetName(PlayerId())

I need to do a TriggerServerEvent(‘Event Name’) Right? If I wanna execute it from a client file?

I don’t 100 % know that out of my mind. You can find that in the Docs.

you can just use GetPlayerName(source)

1 Like

idk if you still need it, but you can download my script and modify it to work for your use (not needed tho)

or

TriggerServerEvent(“someevent”, GetPlayerName(PlayerId())

and make 1 of the server-side script for handler, to trigger to all client (-1) [ maybe calling the prox-chat event ]

My rack and unrack scripts is already made working, its better to download that

I already solved it