✓ Accepted answer
Yes
Sure, this is completely possible. You have the right idea in your module script (by the way, I'm assuming 'module' is your 'GameModes' table), the only thing you're missing is the actual function call (line 8 of your server script)
Returning functions
When you return a function, you're still returning something that needs to be called. It doesn't get executed during the return process. To fix your problem, you could just call it on the same line as your "Run" method with two parenthesis ()
local GameModes = require(script.GameModeModule);
local GameModeTypes =
{
SingleBattle = "SingleBattle",
DoubleBattle = "DoubleBattle"
}
GameModes:Run(GameModeTypes.SingleBattle)()
However
While this does solve your problem, it also isn't very necessary (not in this case, that is). Instead of returning a function, you should just execute the function you pass as the argument as soon as it's called. Here'd be a better example:
local GameModes = {};
GameModes.SingleBattle = function()
print("Single battle!");
end
GameModes.DoubleBattle = function()
print("Double battle!");
end
function GameModes:Run(gameMode)
local func = GameModes[gameMode]
if func then
return func()
else
print(tostring(gameMode) .. " is not valid")
end
end
return GameModes;
local GameModes = require(script.GameModeModule);
local GameModeTypes =
{
SingleBattle = "SingleBattle",
DoubleBattle = "DoubleBattle"
}
GameModes:Run(GameModeTypes.SingleBattle)
Hope this helped, let me know if you have any questions.