How do I pass in my case a few arguments (player and a string) from local script -> server script?

I want to send a player and a string from client → server? How do I do that, I found some tutorials for remote functions but they were all server → client, I couldn’t find client → server? Thanks.

1 Like

From the client to the server you need to do :FireServer(your arguments) in a client script and on a server script you will do:

 event.OnServerEvent(function(the arguments you added)
--code
end)

Don’t I need a remote function?

Hey again :slight_smile:
If you’re using a Remote Event, you need to do this:

--CLIENT
--assuming you wanna do that by pressing a button.
Button.MouseButton1Click:Connect(function()
  game:GetService("ReplicatedStorage"):WaitForChild("YourRemote"):FireServer()
end)

–SERVER

  game:GetService("ReplicatedStorage"):WaitForChild("YourRemote").OnServerEvent:Connect(function)Player)
   --do code
  end)

Yes, if you want to communicate between client → server → client , it’s always better to use a RemoteFunction, rather than couple of remote events.

Also, ‘Player’ has to be the first param when Firing server / Invoking Server. [Only on Server]

Hey, I just want to include 2 arguments and sent them from a local script → server script

Not sure how to do that.

1 Like

Do you have a context script to show?

All you need to do, is to put what you want to change[to be shown on server], and pass it into the event/function.

event:FireServer(argument1, argument2)

event.OnServerEvent(function(player, argument1, argument2)

end)
2 Likes

An example:

--CLIENT
script.Parent.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage"):WaitForChild("RemoteFunction"):InvokeServer(script.Parent.Text,script.Parent.TextColor3)
end)

--SERVER
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player,Text,Color)
	print(Text)
end
1 Like

IMPORTANT:

As I’ve said above, when you’re using InvokeServer(), FireServer() or FireClient(), the Player instance always has to be the first param[ on server call only for InvokeServer and FireServer, and on both client and server for fireclient]

Thus,
if you’re using InvokeServer(), and you want to pass 1 or more params, remember that you’ll have to put that amount of params + 1[ of the player] on the server call.

2 Likes

As you can see in this example,

I passed 2 arguments [ Text and Color],

And on the server, I put 3 params [ Player,Text and Color].
Thats because InvokeServer() requires the first param to be the player. :slight_smile:

Ah nvm, I thought to pass arguments you needed to use a remote function, and I was confused why I needed to send client → server → client.

I’ve got it now. So player is automatically an argument? I noticed you don’t have to assign that, it’s like built into the event? Is there any other arguments like that predefined?

Yes, when using InvokeServer() or FireServer(), the first argument is automatically the player [on the client event], on the server,you’ll need to put it always as the 1st param.

Not to my knowledge, Player is the only one I know is predefined when using remotes

Using RemoteFunctions has an advantage on using RemoteEvents, simply because with remotefunctions, you can return from the server to the client and do more cool stuff [unlike remoteevents, where you’ll need a couple of remotes or some extra arguments].

For e.g : Twitter Codes system, uses remote functions, what it does:
A) Invokes the server when the player redeems a code.
B)Checks if it’s a valid code, if it is, it returns ‘REDEEMED’ or ‘ALREADY REDEEMED’.
C)If it’s not a code, it’ll return ‘Invalid Code’

2 Likes

One more question

Can I not change any GUI stuff with a server script?

[Edit:]

Like what I’m trying to do is I have a mission GUI button. If you click accept, the script checks if you can do the mission (the max limit is 3 missions at a time)

So I didn’t wanna do this check all in the local script, because I assume a hacker could exploit that?

So I figured I’d do the check and do all the GUI stuff on the server script after the button is pressed via remote event. Do I need to use a remote function to basically tell the local script if this person can do the mission?