✓ Accepted answer
Referring to your "elseif" format
In Lua, there is no switch statement like other programming languages, so the whole "elseif" thing is the best way to do it. While there are other ways like using tables to connect functions together, it might just make it more complicated:
local number=1
function switch(c)
local swtbl = {
casevar = c,
caseof = function (self, code)
local f
if (self.casevar) then
f = code[self.casevar] or code.default
else
f = code.missing or code.default
end
if f then
if type(f)=="function" then
return f(self.casevar,self)
else
error("case "..tostring(self.casevar).." not a function")
end
end
end
}
return swtbl
end
local number = 1
function onMouseButton1Click()
switch(number):caseof{
[1] = function() return "It's 1" end,
[2] = function() return "It is 2" end,
[3] = function() return "dudeboy, it's 3" end
}
number = number + 1
end
script.Parent.MouseButton1Click:connect(onMouseButton1Click)