Hiya! One of the questions that has been going through my mind recently is: "Is there any way of calling a function or variable using a string, for example (Pseudo Code):
local function test()
print("Hello!")
end
toFunction("test")()
I’ve had a quick look through the forum and couldn’t see anything similar to this. The easiest way of doing it would be something like:
local function test()
print("Hello!")
end
local functionString = "test"
if functionString == "test" then
test()
end
but I really don’t want to do it that way since it would take a lot of space doing elseif statements for each function and also looks messy and unprofessional!
Thank you so much for reading! Any help would be appreciated!
This is not recommendable, as the use of global variables in itself is already discouraged, and the use of getfenv disables some of Luau optimizations.