String to function

i want to convert strings to functions, for example:

function abc ()
print("hello")
end

--call the function here using a string
local variable1 = "a".."b".."c"
???? --how to call function from variable1

That’s not possible.

(Roblox Character Limit)

you would place the function in a table, as if it were a modulescript, and call the function through the table using []. this is a common practice for admin scripts


local FunctionsList = {}

FunctionsList.abc = function(Paramaters)
    print("i am a function"!)
end


FunctionsList["abc"](Paramaters)

U can try this

local Variable = "A"

local Reqire = require(script[Variable])

Reqire()

Module Example:

return function()
	print("A")
end

How it look in explorer:

image


OR this

local Variable = "A"

local Reqire = require(script.Func)[Variable]

Reqire()

Module Example:

local module = {}

function module.A()
	print("A")
end

function module.B()
	print("B")
end

function module.C()
	print("C")
end


return module


How it look in explorer:

image