how do i find the text thats in a textbox. for example, if a player typed a secret code, it would give them an item. but how do i locate the text thats in the box.
✓ ANSWER ACCEPTED
how to find the text thats in a text box?
2 answers
✓ Accepted answer
We can use the FocusLost event to find what the player put into the text box after they have finished typing.
local code = "bork" --The code the player would type in for a prize
TextBox.FocusLost:connect(function(entered) --When the player clicks away from the textbox or presses enter, they fire the FocusLost event and return whether or not enter was pressed.
if entered and TextBox.Text:lower() == code:lower() then --if the text in the textbox is the same as the code, then run the following code. we use :lower() to make the string lowercase, so if the player typed "Bork" instead of "bork" then they would still get the prize. "entered" is there to detect if the player pressed enter or not.
print("Correct Answer")--code would go here to give the player their prize
end
end)
First you'd want an event that detects if the player is finished typing, FocusLost. If you wanted to find the text that player inputted in the textbox, you'd use TextBox.Text.
local code = "code"
script.Parent.FocusLost:connect(function(text)
if text and script.Parent.Text == code then
-- code consequences
end
end)
2 comments
0
You're comparing a string to a table.
0
uh, can you explain it more. And have it so that it works?
This discussion is preserved as it was. New answers, comments, and votes are closed.

7 comments
thats in the output, and it doesnt print the thing
Edited. Make sure to change "TextBox" to the textbox you're wanting to check for.
in the output, it says lower is not a valid member of TextBox. and it means the textbox i named codebox. the naming is ok. but it still doesnt work.
make sure line 4 reads TEXTBOX.Text:lower(), and replace TEXTBOX with a reference to the textbox. I think you must've replaced ".Text" too.
i used script.parent, and it worked. why does script. parent work when game.startergui.screengui.textbox not work? thank you btw
Two things: Editing the gui in StarterGui doesn't edit the gui the player is looking at. It edits the gui in StarterGui. The gui the player is looking at is a copy of that gui. Secondly, make sure StarterGui is referenced right (case sensitive). StarterGui ~= startergui