Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I Send over strings via Remote Events? Client-Server

Asked by 2 years ago

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:

-- Local Script

local RepS = game:GetService("ReplicatedStorage")


-- let's say that the string is already defined and I am going to send it over to the server script
local TheStringIWantToSendOver = "ThisIsTheMessage"

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:

-- Server Script

local RepS = game:GetService("ReplicatedStorage")



RepS.MyRemoteEvent.OnServerEvent:Connect(function()

    local MyVariable = "" -- How could my string from the local script end up here?

end)

1 answer

Log in to vote
1
Answered by 2 years ago

The remote event on server when gets triggered by the client it receives an first argument which is the player.

Server:

RepS.MyRemoteEvent.OnServerEvent:Connect(function(player, variable)

  print(variable) --to make sure the server received it
end)

Client:

local TheStringIWantToSendOver = "ThisIsTheMessage"

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!

0
Thank you so much for giving a good example, it worked perfectly! johnoscarbhv1 137 — 2y
Ad

Answer this question