Is it possible to type a code or phrase into a textbox to make a UI not visible

  1. Is it possible to type a code or phrase into a textbox to make a UI not visible

  2. I want the player to type a code or phrase in a textbox that can make the UI not visible

  3. I have searched the DevForum and have found no answers.

Check when your text box unfocused, and if the text is equal to what you want, set the ui visible property to false.

1 Like

Yes, you can make a script that detects text change inside the ui. This can then be used to check for a phrase, if the phrase is matching, set the gui property to false.

local TextLabel = script.Parent.TextLabel

TextLabel.TextChanged:Connect(function(newText)
    if newText ~= TextLabel.Text then
        TextLabel.Visible = false
    end
end)

This is just to track change, after change, use an if statement to check if the newtext is a phrase.

You need to connect the TextBox's FocusLost property to a function that checks what’s inside it. If it finds the phrase then you can run a piece of code that turns the ui’s Visibility property to false.

There is no text changed signal.

The OP is using a TextBox, not a TextLabel. Those are two different ui elements. Unlike the TextLabel, the player can type in text into the TextBox.

I see,

local TextBox = script.Parent.TextBox

TextBox.FocusLost:Connect(function(enterPressed)
    print(TextBox.Text)
end)
--Use this as template code and add check statements for phrases, to set visibility, it will fire when the player clicks off the box, which indicates they are done typing.
1 Like

Make sure to use it in a local script, since you can’t see what the player types in server-side. If you need to have the effect on the server you can use a RemoteEvent.

Thanks, Mate you’re a legend

All I had to do was this

local TextBox = script.Parent
local UI = script.Parent.Parent
local Text = "123"

TextBox.FocusLost:Connect(function(enterPressed)
	if newText ~= TextBox.Text then
		UI.Visible = false
		end
	end)

That code’s wrong.

newText doesn’t exist as a variable. To get the textbox’s text you need to reference TextBox.Text. Also, the ~= operator should be the == equality operator instead, since you’re checking if the textbox’s text equals a phrase. Over all, this is how it should look instead.

local TextBox = script.Parent
local UI = script.Parent.Parent
local Text = "123"

TextBox.FocusLost:Connect(function(enterPressed)
	if TextBox.Text == Text then
		UI.Visible = false
	end
end)
1 Like

Yeah that fixed the issue that it would just make the UI not visible by clicking

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.