How would I send text through a remote event?

I know this might really be a dumb question, but how would I send text [from a textLabel or a textBox] from client > server?

Would I do something like this:

game.Car.RemoteEvent:FireServer(script.Parent.Text)

and if it’s the correct way to do it how would I receive the text from the server script handling the remote??

1 Like

Yes, this is not a bad way to do it. You may want to check the text sent for bad words and such with TextService though

1 Like

You could use RemoteEvent.OnServerEvent (sorry for the lack of links, on mobile right now, you can go to the roblox Developer Hub to look up OnServerEvent)

2 Likes

Yes, you can.

The server will receive the message from the client. The first parameter is the player and others are the arguments.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, text)
    print(player, text)
end
3 Likes

Make sure to use :FilterTextAsync when doing it to avoid getting moderated.

2 Likes

Okay, but the thing i’m confused about is on the ServerScript, on this part

(player, text)

How would the script know that it’s receiving the specific ‘text’ argument? Since I don’t see anything like:

local text = gui.Text

Sorry if you are confused I don’t know how to word this

Because you have already defined the text and the server has received the only defined text. The text, which you connected with a RemoteEvent, will be transferred to the server. If you are still confused about this, in your both local script and server script use

print(player, text)

OnServerEvent will automatically find the player and the text. Imagine it is being stored in the RemoteEvent (something like this) until it is used in the script.

1 Like

Ah, so I’m guessing it sends it to the server and you can name it whatever you want but it has to be in order?

I mean, in your local script you can just use the argument,

game:GetService("ReplicatedStorage").RemoteEvent:FireServer(text) -- You can just send the text

Server script

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(player, text) -- These parameters must be in order.

For example you are trying to send 6 arguments from a local script. Then in the server script you should use 7 parameters. They are the player and the arguments.

3 Likes