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

How can I get text from a text box?

I have a text box that I want people to enter their text in. After they press enter, it is supposed to press enter and fire a remote event. The text should then be printed into the output, but it prints nil instead of what the player entered. How would I fix this? By the way: This is on a surface GUI. Here is my button script:

script.Parent.MouseButton1Click:Connect(function()
	local text = script.Parent.Parent.TextBox.Text

	game.Workspace.Events.Text:FireServer(text)
end)

Here is my print script:

script.Text.OnServerEvent:connect(function(plr, text)
	print(text.Value)
	end)

2 comments

0

Use RemoteEvents in ReplicatedStorage, scripts for RemoteEvents in Workpsace or ServerScriptService.

0

Also don't forget to use FilterStringAsync either, it won't error in testing mode but if you don't filter it, Roblox will disable the place till you fix it. It basically filters the text to make sure it's safe for users to see/read. Here is a link to the wiki about it, https://developer.roblox.com/articles/Text-and-Chat-Filtering

2 answers

✓ Accepted answer

localscript

script.Parent.MouseButton1Click:Connect(function()
    local text = script.Parent.Parent.TextBox.Text

    game.Workspace.Events.Text:FireServer(text) -- fire the textbox's Text in the 2nd arg
end)

serverscript

script.Text.OnServerEvent:Connect(function(plr, text) -- use Connect not connect
    print(text) -- prints the text
end)

text doesn't have a value

2 comments

0

I tried this, but it printed nothing then.

0

nvm

I suggest you rubber duck your code. Say it out loud, line by line. You're listening to a different event than what you're firing.

2 comments

0

Oh wait sorry

0

Put this in a comment, not in answer area.

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