How to detect whether a player has typed anything in a text box

So I’m trying to make it so if the player hasn’t typed anything into the textbox, it’ll appear some sort of error message where it tells you to type, but idk how to do so.

This is my script right here:
(I just need the coding for the detection,I’m fine with the other coding/actions)

    local Suggestion = SuggestionBox
    local Submit = Submit button 

   if Suggestion.Text == "" then
        	Error:play()
        	
        	Submit.BackgroundColor3 = Color3.fromRGB(252, 0, 6)
        	
        else
        	
        	Submit.BackgroundColor3 = Color3.fromRGB(123, 200, 255)
        	
        end
3 Likes
local Textbox = -- were

Textbox:GetPropertyChangedSignal("Text"):Connect(function()
  print('here we go again')
end)
2 Likes

now whenever I type something the error message appears instead.
I want to make so when the player types nothing and presses submit,THEN the error message appears

1 Like

Try this in a local script. Change textBox to where ever the box is.

local textBox = script.Parent



textBox.FocusLost:Connect(function()
	print("plr typed in box then pressed enter text: ".. textBox.Text)
end)
4 Likes

Try something like this:

local box = -- textBox
local submit = -- submit button

submit.MouseButton1Click:Connect(function()
   if box.Text ~= "" then
      -- submit
   else
      print("You have to type something.")
   end
end)
3 Likes

Thanks for helping.
So I just want to ask,what does ~= do and what does it means

1 Like

~= means not equal. Essentially, we check if the text inside the texbox is not equal to nothing at all. If it is not equal to literally nothing, we know there is some text and we can submit.

1 Like

why not ‘if not (detection)’ then?

1 Like

That wouldn’t work for text. if not statements only work for checking if variables are false or nil.

local variable = false

if not variable then
   print("The variable was equal to false or nil.")
end
1 Like

OHHH no wonder it wasn’t working for an event I’m working on.

This is very helpful, thanks for your explanation.

2 Likes

Wait but for example

If something.visible = not True

why not

If something.visible = false

Theres no point in doing

not true

when you can do

not variable

or

variable == false

Its basically for easier readability.

-- you can also check for whitespace
if textBox.Text:gsub('    ', '') ~= '' then
  --submit
else
  print('You can\'t leave this textbox empty')
end
2 Likes