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

TextBox printing the text twice in output?

Asked by 8 years ago

I'm trying to create a code GUI. But whenever I use the Changed event, it prints the code twice in the output, instead of once.

codebox.Changed:connect(function(tex)
    if codebox.Text == "B3TA" then
     print("INPUTTTT")
     end
end)

1 answer

Log in to vote
1
Answered by 8 years ago

Suggestion:

You may wanna use the argument the event returns, which is a string value of the property that's been changed.

Explanation:

See, this event will log every single property that changes in the TextBox. And sometimes, more than 1 property can change at a time.

For example, every time a text changes in a text box, so does a property called "TextBounds", which represents the size of the text. Thus, invoking the event twice (because of the text, and size changing).

Example:

So, we can easily fix this problem with a simple if statement using the argument our Changed event returns, like this:

-- Assuming this script is inside the TextBox object.
local codebox = script.Parent

codebox.Changed:connect(function(property)
    if property == "Text" then
        print('Text changed to: '..codebox.Text)
    end
end)

Hope this helped.

Ad

Answer this question