Hello, so I've got a little problem In my game I'm making a feature that makes it so a player can type a string into a textbox and then it will be sent over to a script, but there is one problem that I encountered and that is that I have no way of sending over the string. I know about remote events and stuff but I can't seem to wrap my head around how you are supposed to use the parameters in the remote Event.
Here is an example of what I'm trying to do:
Local Script:
1 | -- Local Script |
2 |
3 | local RepS = game:GetService( "ReplicatedStorage" ) |
4 |
5 |
6 | -- let's say that the string is already defined and I am going to send it over to the server script |
7 | local TheStringIWantToSendOver = "ThisIsTheMessage" |
8 |
9 | RepS.MyRemoteEvent:FireServer() -- How would I be able to send over the string in line 7 through the Remote Event and for the script to receive the information. |
Server Script:
01 | -- Server Script |
02 |
03 | local RepS = game:GetService( "ReplicatedStorage" ) |
04 |
05 |
06 |
07 | RepS.MyRemoteEvent.OnServerEvent:Connect( function () |
08 |
09 | local MyVariable = "" -- How could my string from the local script end up here? |
10 |
11 | end ) |
The remote event on server when gets triggered by the client it receives an first argument which is the player.
Server:
1 | RepS.MyRemoteEvent.OnServerEvent:Connect( function (player, variable) |
2 |
3 | print (variable) --to make sure the server received it |
4 | end ) |
Client:
1 | local TheStringIWantToSendOver = "ThisIsTheMessage" |
2 |
3 | RepS.MyRemoteEvent:FireServer(TheStringIWantToSendOver) |
Note that on the cllient you don't gotta speciffy player argument, roblox automatic does that for you on client but not on server. If it didn't work let me know!