How to properly pass info through arguments with RemoteEvents (LocalScript to ServerScript)

I just want to learn how to use arguments/parameters the right way to pass information between RemoteEvents.

  • Local Script:
local localNumber = 20

buyButtonRushies.MouseButton1Click:Connect(function(player, number)
player = plr
number = localNumber
game.ReplicatedStorage.RemoteStuff.Test:FireServer(player, number)
end)
  • Server Script:
game.ReplicatedStorage.RemoteStuff.Test.OnServerEvent:Connect(function(player, number)
print(number)
print(player)
end)

Both prints in the Server Script returns the player name instead of the Player Name and localNumber value

4 Likes

The player is automatically passed as the first argument in FireServer, so you should just replace that line with
game.ReplicatedStorage.RemoteStuff.Test:FireServer(number)

7 Likes

Oh, i knew that the first argument would always be the “Player” but i didn’t knew that it was pointless setting the player in the parameters, it worked, thank you :slight_smile:

1 Like

Calling FireServer on the client will automatically pass the player who passed the fired the event as the first argument of OnServerEvent, thus the first parameter of the function

What you’re doing is attempting to pass the player and number to the parameters of OnServerEvent, but the parameter number would actually be the player, since it was passed in FireServer. You can remove the player from FireServer

I question why you made parameters for MouseButton1Click - MouseButton1Click doesn’t pass anything as an argument, therefore, it has no parameters. This may lead you to think that it actually passes parameters

1 Like

It’s not pointless, but rather, you don’t at all. Otherwise the player is your second argument.

2 Likes

MouseButton1Click doesn’t pass either of these as arguments, so you can remove it to be function() instead. You also wouldn’t need to re-assign them via player = plr and such because you can already access variables from outer scopes by name normally.

2 Likes

Now i see, i really appreciate all of you explanations guys, now i have a better understanding on how this should work, again thank you all for the help cause i really was having a hard time trying to get it haha ^^

1 Like