Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to grab input from a textbox using a server script?

Hello. I use guis. If you used them before, you will know that a player typing in a textbox makes words show up obviously, BUT its a local textbox. If you use a server script (a normal script) and try to find what the textbox input is it will end up blank.

Can someone pelase explain to me how to use a server script to grab a specific player's input of a textbox? thanks

4 comments

0

do :GetProperyChangedEvent("Text")

0

You have to use the Text value as an instance. For Instance if my Text GUI means that my life is going down the hill then it is what it is

0

omg, how will remote events work? they are events, this is not an event im trying to figure out how to find local text

2 answers

✓ Accepted answer

As Block_manvn said, use a RemoteFunction. A RemoteFunction allows a client to get something that they can't access by using the server, then the server brings the information back to the client, and vice versa. If you don't know what a client is, a client is pretty much on the player's side. The client is what the player sees on their screen. The server is from ROBLOX. It controls what happens in the game.

So you're correct, the server cannot grab from a TextBox because it's local to the client. This is why you must use a RemoteFunction. A RemoteFunction will allow the server to tell the client to get this information for it. Make sure you insert a RemoteFunction somewhere. I'll just pretend mine is in ReplicatedStorage.

Server Script

-- Let's say 10 seconds have passed because there was a timer
game.ReplicatedStorage.RemoteFunction:InvokeClient() -- Invokes the client to do its job

Local Script

game.ReplicatedStorage.RemoteFunction.OnClientInvoke:Connect(function() -- Client is making the event happen
	local text = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox.Text -- LocalScript knows what is in the TextBox
	return text -- Returns text to the Server Script so it knows what's in the TextBox now
end

ServerScript (same script as before but adding something because text is returned)

-- Let's say 10 seconds have passed because there was a timer
game.ReplicatedStorage.RemoteFunction:InvokeClient() -- Fires the client to do its job
	 
	print(text) -- That's just something you can do with the text now

Hope this helps! If you don't want to return information, you can use a RemoteEvent. It's not that different. You can go to the link that Block_manvn provided to learn more.

You should not use Server Scripts on the Client. If you want to tell the Server something that happens on the Client. Use RemoteEvents. Create a RemoteEvenet in ReplicatedStorage and name it whatever you want. Then use this code:

LocalScript

local remEvent = game.ReplicatedStorage.RemoteEvent -- change this to the name of your RemoteEvent

local textBox = script.Parent -- change this to where your TextBox is located

textBox:GetPropertyChangedSignal("Text"):Connect(function()
	remEvent:FireServer(textBox.Text)
end)

So :GetPropertyChangedSignal() is an Event that waits for the property given, in this case Text, to change. When it does, we create a function and Fires our RemoteEvent with the Text as an argument. Then this;

Server Script

local remEvent = game.ReplicatedStorage.RemoteEvent -- change this to the name of your RemoteEvent

remEvent.OnServerEvent:Connect(function(player, text)
	print(player.." wrote "..text)
end)

This time, we get the Event and wait for it to fire. When it does, we get the arguments sent. Which are player and text. You can name those whatever you want. The player argument is automatically sent when a RemoteEvent is fired from a Client so that the server should know which player who fired it. Then the player argument is followed by the arguments sent from the Client, in this case the text. We then print the player and the text to show that we recieved the Event.

2 comments

0

thx so much i never knew this existed. the creating arguments part.

0

No problem, happy to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.