3 conditions in an if statement

I am trying to make an if statement with 3 conditions.

Instead of using this,

if randomString == "Hello" or "Good" then
    if randomString == "Bad" then
        print("OK")
    end
end

I would like to make it something like,

if randomString == "Hello" or "Good" or "Bad" then
    print("OK")
end

I am aware that the script above will not work.

1 Like

Your 2nd script won’t work. It’d print ‘OK’ for every string you’ll put as ‘randomString’.

Try this

if randomString == "Hello" or randomString == "Good" or  randomString =="Bad" then
	print("OK")
end

I was struggling with this issue for a long time.
Thank you so much! :smiley:

1 Like

Another way you could do, is

local myWords = {"Hello","Good","Bad"}


for index,word in pairs(myWords) do
    if randomString == word then
       print("OK")
    end
end

In here, you’re looping through yourWords table, and check if ‘randomString’'s value can be found there. If it is, then print ‘OK’

if table.find(myWords, randomString) then

Correct, that’s the brief way to do that