How would I call a module function using a string?

This might be simple, but I’m not sure how to do this.

I have a folder that is filled with string values of functions in a module script. I use a variable to get a random string from the folder. I then want to call the module function that has the same name as the string. How would I do this?

module.“STRING FUNCTION HERE”()

Easy stuff.

local m = {}

function m.doSomething(Param)
   print(Param)
end

return m
local m = require(module)

m["doSomething"]("hi")

Modules are essentially tables. In fact, a required module is almost exactly what it returns. In this case, a table of functions.

1 Like

I have the functions inside another module script though, would this still work?

Yup! You’d just have to require the correct path to that module script :slight_smile:

1 Like

Great! Thank you both for helping out

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