How does this event can identify a player?

This is hard to me to explain since this is hard to me, i have been working on my game, and the game is using some scripts from an Open-Sourced game (Shops, Game Round System, Etc.) and i was reading the Shop scripts and i got confused on something:


So, this is the script where identify when the player clicks on the pet to buy it and fire a server.

function fire(player,pet)


And this is the script where the player gets the pet.

So, my question is how does the script identify a player? Because the PetAdd event is sent with Buttons.Name, but how does the other script identify player and pet? If you want i can give you the full script.

when using an event, the first thing in the parenthesis is always the local player, so the part:

function fire(player,pet) -- "player" is the person who clicked the button

Here is a remote event article for more info:

I thought LocalPlayer can be used in LocalScripts, and this is a script in Workspace.

if you look at the article it can give you a better understanding of this, but remote events can carry data over from the client to the server or the server to the client, so always the local player will be the first thing defined in the parenthesis.

Well, pet is a variable in the player as i saw, so (player, pet) is refering to that value?

the “player” refers to the local player and yes the pet refers to the actual pet data that is sent to the server.

Right, and now my question is there’s written (Buttons.Name)? It’s the pet name but i can’t see nothing in the script that is mentioning Buttons.Name.

Button is not defined in the GUI? it should be something, otherwise it would be sending a nil value to the server.

When a player does an OnServerEvent the first thing the server gets in the message array is the player.

So the server gets 2 messages. First it gets who sent it. Then it gets the message. The connect(fire) passes the entries to the fire function.

Sending to the client is the reverse. You need to have it send (player, firstMessage) to tell the server who to send it to, and the player won’t get the player message, so it will just get the firstMessage.


Do you need the entire script? Maybe i didn’t read something and reading it again will not make me understand.

Well Steve just gave you the solution, so it is not necessary, but somewhere in there, “Button” should be defined in that script, which is sending the pet data to the server. Steve literally made what I was trying to tell you simpler.


To explain this simply:

RemoteEvent.OnServerEvent:Connect(function(a, b, c)
--a is player, b would be the 1st parameter sent...

When the event is fired by a player, this first parameter (a) is set to the player that fired it and the rest of the parameters are filled onwards.


a would be the player.
b would be 1.
c would be 2.

1 Like