"if string == string" returning false when its true inside textbox

So I was making a part of a game where you could type in a textbox and if its correct it’ll print it.
Here’s my code:

script.Parent.FocusLost:Connect(function()
	if script.Parent.Text == "test" then
		print("Working")
	else
		error("Problem occured again.")
	end
end)

When I put test into the textbox, it does the error I tried adding prints and it says that everything is correct the text is test and test = test so im not sure what the problem is, with knowing how to script, this is the weirdest thing I have seen. :slight_smile: Thanks!

By the way I looked on google and found no similar problems.

To see what’s going on more, I suggest you print what the actual text is.

Printing the actual text prints test

Are there any spaces when it’s printed?

Can you print the length of the text?

Found the problem (maybe), there was a report in #platform-feedback:engine-bugs that there is a carriage when you press enter in the textbox. Link is here:

1 Like

The length of the text prints 5 for some reason.

Perhaps this is related to the recent Roblox bug? Have you tried setting anything up to remove the special control character (which’s what the bug is)?

Edit @Quwanterz beat me to it lol.

Where is the special control character located at the beggining or the end?

Try this:
print(game.HttpService:JSONEncode(script.Parent.Text))

You can remove the control character by using it’s pattern %c, in combination with gsub to remove it.
For example, in the context of your code

local Input = script.Parent.Text:gsub("%c", "");

it still happens (character limit)

Still happening. Thanks…

I think I might have a solution to this problem, since the %c check didn’t work.

local ContainsControlCharacter = script.Parent.Text:gsub("%w", ""):gsub("%p", "") ~= "";

What this essentially does is remove any letters, numbers and punctuation, and compares the result to an empty string; if the string isn’t empty, it has the control character, thus returning true. If not, it’ll return false.
For use in your code, the following could be tried

local Input = script.Parent.Text;
local ControlCharacterCheck = Input:gsub("%w", ""):gsub("%p", "");
if (ControlCharacterCheck ~= "") then
    Input = Input:gsub(ControlCharacterCheck, "");
end
print(Input == "test");

It’s a long shot, and I might be overcomplicating this, but I think it’s worth a try.

I hope this helped. :slight_smile:

Edit
You’re very much welcome! I’m so glad this solution worked. :smiley:

Thank you so much! I thought I would have to shut down my games!

1 Like

Happle, I like to say please come back.