Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TextBox printing the text twice in output?

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

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.