Is there a Way to turn an if statement into a Function?

I’m wondering if I can turn this code into a Function:

if SlotNumber == "Slot2" then
end

I need it to be a function so I can call the exact part that has a Child.SlotNumber.Value = “Slot2”.
So I can parent that Specific part in a table somewhere else.

I’m not too sure what you mean. You’d have to provide more details so I understand your specific use case, but you could always do something like this:

local function compare()
     if SlotNumber == "Slot2" then
          return true
     end
     return false
end
3 Likes

Doing comparisons like that isn’t necessary. Since == evaluates into a bool, you can just use it as such. Also, I assume OP will want this parametrized to work in more than just 1 context.

local function compare(SlotNumber)
    return SlotNumber == "Slot2"
end

However I’d like to know the specific use case because it seems easier to just do == wherever needed.

4 Likes