Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if player typed something in a TextBox?

Asked by
CMB1048 25
1 year ago

I have been trying to do it for so long but nothing is happening when I put in the text

if TextBox.Text == "H+MbQeTh" then
        print("hi")
    end


0
is anybody going to help me? CMB1048 25 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

You will need to put the if statement inside an event or loop. Putting it inside a loop (such as a while loop) means that it will loop indefinitely, therefore, constantly checking the condition of the if statement; this is not recommended as it will waste resources and will cause lag, especially since there are better ways to do this (such as using events). You can check what events are available for an object by searching for it in the Roblox documentation and navigating to events.

As you can see here, from the documentation, the TextBox has an event FocusLost which will fire when the client clicks off the TextBox.

This event also has two parameters, the first being a boolean indicating whether the client pressed Enter to lose focus; the second parameter is the input object that caused the loss of focus.

TextBox.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLoss)
    if TextBox.Text == "H+MbQeTh" then
        print("hi")
    end
end)

If you want to check the condition of the if statement when the client types into the TextBox, you can use the GetPropertyChangedSignal method which will return an event whenever the Text property changes.

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
    if TextBox.Text == "H+MbQeTh" then
        print("hi")
    end
end)
Ad

Answer this question