Question
How do you get a text value from a gui with remote events?
Answer
Case 1: Remote Functions
You ask it in a way such that you would want to request the client to return a value, so I suggest you look into RemoteFunction's.
https://developer.roblox.com/en-us/api-reference/class/RemoteFunction
A RemoteFunction is essentially a RemoteEvent that will return a value when the client (or server) responds with one.
You would want to setup a system such that you could reference a GUI member, and return the text of that member from the remote event.
In this scenario I am going to assume the GUI the player owns came from StarterGui and therefore was cloned on the server to the player's GUI.
This means the server can reference the GUI objects, but due to how replication works will not see changes in most properties.
So the server could pass reference to the GUI object and the client would index the given GUI object and return the value of the Text property.
- If you only need to get the
Text from a specific value from a client you will not need to pass a reference, just store a dedicated reference on the client and use that reference.
In code it could be something like this:
Use of passed reference:
We pass a reference from the server.
local remoteFunction = ...
remoteFunction:InvokeClient(someClient, reference)
Client will use the passed reference variable.
local remoteFunction = ...
local function handleInvoke(reference)
return reference.Text
end
remoteFunction.OnClientInvoke = handleInvoke
Use of dedicated reference:
Server just invokes the client to get the Text of a dedicated reference.
local remoteFunction = ...
remoteFunction:InvokeClient(someClient)
Client uses their dedicated reference variable to return the Text the server wants.
local remoteFunction = ...
local reference = ...
local function handleInvoke()
return reference.Text
end
remoteFunction.OnClientInvoke = handleInvoke
Case 2: Remote Events
If you would like the client to send the text to the server and the server preforms some action based off that text I would prefer using a RemoteEvent.
All you would need to do is just send the value of the Text property of your TextLabel or TextBox through the :FireServer method of the remote event.
RemoteEvent:FireServer(TextBox.Text)
2 comments
Thank you very much!
You are welcome!