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

Script thinks everything is the given Text, why?

Hey! I saw some people using these "Templates" to make the question more readable, so I do it as well.

Problem

The Script always thinks every text is the specific text given in the script.

Explanation

I am trying to make an Answer GUI. The script should detect if the given answer is correct. But it always prints "Correct!", even though the answer is wrong.

Script

if answer == "AnyDoge" or "Anydoge" or "anyDoge" or "anydoge" then
			print("Correct!")
			iscorrect = true
		else
			print("Wrong!")
			iscorrect = false
		end

2 comments

0

need to do ... if answer == 'AnyDoge' or answer == 'Anydoge' or answer =='anyDoge' or answer == 'anydoge' then

1

Also you don't have to have 10 options. You can do: answer:lower() and it will make all characters low then compare it to answer you are looking for.

1 answer

✓ Accepted answer

I see this problem a lot. There's a BIG difference between answer == "1" or answer == "2" and answer == "1" or "2".

Firstly, you need to know how the condition is met in if-statements. If **any **value in an if-statements condition is not false or nil, the condition is met. This is why you need to check equality between two values. A string is ALWAYS equal to itself. If you isolate a string in an if-statement, the condition is always met. the 'or' statement separates conditions.

What you should be doing, is:

if answer == "AnyDoge" or answer == "Anydoge" or answer == "anyDoge" or answer == "anydoge" then

because you're checking equality between the answer and a string.

Also, you can reduce your if-statement to 1 condition using the *lower *method of string, like so:

if answer:lower() == "anydoge" then

Hope it helps.

2 comments

0

In other words, separated conditions in an if-statement cannot be related.

1

Thanks.

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