How to have or without duplicating a == check?

I dont know how to explain this well but lets say I have this

if input.UserInputType == Enum.UserInputType.MouseButton1 and thing == true then

and I wanna add or input.UserInputType == Enum.UserInputType.Touch to it without copying the and thing == true how would i do it?

if input.UserInputType == Enum.UserInputType.MouseButton1  and thing == true  or input.UserInputType == Enum.UserInputType.Touch  and thing == true then

so i dont have to have the thing == true thing duplicated twice, im trying to do this in one line btw.

Just define thing == true as a separate if statement before the other if statements.

if thing == true then --> moved to a new if statement before the next if statements
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        
    end
end

right but i have a lot of these if statements so i cant do that, is it possible to do it in one line or a quicker way?

You could also have

if thing == true and (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch)
2 Likes
local acceptedInput = {
    [Enum.UserInputType.MouseButton1] = true,
    [Enum.UserInputType.Touch] = true,
}

local function MyCoolFunction(input)
    if thing == false then return end
    if acceptedInput[input.UserInputType] == nil then return end
    print("thing == true and input == MouseButton1 or Touch")
end
1 Like

you can do something like this:

if not thing then
    return
end

or
if not thing then return end