The reason the First Argument being the Player is that you are sending Data from the Client to the Server, and on the Server, you cant access the Player, This only Applies for OnServerEvent
For OnClientEvent, You are sending Data from the Server to the Client, when firing, you have to specify what player its running for, or use RemoteEvent:FireAllClients() to fire for all Players
This is from the First Paragraph of the Documentation:
A RemoteEvent is designed to provide a one-way message between the server and clients, allowingScriptsto call code in LocalScriptsand vice-versa. This message can be directed from one client to the server, from the server to a particular client, or from the server to all clients.
Replace the RemoteEvent with a RemoteFunction and place these scripts:
--The Local Script
local RemoteFunction = script.Parent.RemoteFunction --Path of the RemoteFunction
local gunName = "Glock 17"
RemoteFunction.OnClientInvoke = function()
return gunName
end
RemoteFunction:InvokeServer()
--The Server Script
local RemoteFunction = script.Parent.RemoteFunction --Path of the RemoteFunction
RemoteFunction.OnServerInvoke = function(Player)
local gunName = RemoteFunction:InvokeClient(Player)
print(gunName, Player)
end
There’s no need for a RemoteFunction if the local script doesn’t need any information returned.
What @DasKairo is trying to say is that FireServer automatically passes the player in as the first argument to OnServerEvent, so you don’t need to do it manually when you call the function. The code should look like this:
Local script:
local gunName = "Glock 17"
event:FireServer(gunName)
The reason why it is doing this is because you have Player in your :FireServer(). You do not need “Player” in your :FireServer() because it already passes it automatically. So just remove the "Player " in the parentheses of :FireServer() and it should work.
Basically, what is happening is because the :FireServer() passes the player automatically, when you have :FireServer(Player, Classes), and then you have (Player, Classes) in your OnServerEvent, Classes in the :FireServer() is actually being assigned to the Player in the OnServerEvent. That’s why it’s printing your name.
If you found my answer helpful, be sure to mark it as the solution!