PcoWSkbVqDnWTu_dm2ix

Get User Text Input

Get User Text Input

Mar 30 2021, 5:21 AM PST

Problem

You want to read the current input (what the player has typed) from a TextBox.

Solution

Create a TextBox and use the TextBox/FocusLost event.

script.Parent.FocusLost:connect(
	function(enterPressed)
		if enterPressed then
			print(script.Parent.Text)
		end
	end
)

Discussion

The TextBox/FocusLost event fires when the user either clicks outside of the TextBox or presses the Enter key. In this case, we check to see if Enter was pressed and then print the value of the current TextBox/Text property of the TextBox.

Tags:
  • input
  • text
  • ui
  • script