Is there a more efficient way of finding a ModuleScript function instead of doing elseifs

Hi! This is more of a nitpick than a problem I have but I want to see if there is any other way of doing what I want.

So, I have a module script used for functions, and I want to run a function when a string that’s the same name as the function’s name something like a :FindFirstChild, instead of doing elseif’s a lot.

--instead of something like:
local stringexample = "function1"

if stringexample == "function1" then
   requiredmodule.function1()
elseif stringexample == "function2" then
   requiredmodule.function2()
else
   blahblahblah
end
local Functions = {
    ["function1"] = function()

    end, 

    ["function2"] = function()

    end
}

local Str = "function1"

if (Functions[Str]) then 
    Functions[Str]()
else 
    warn("function not found.")
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.