I have been writing and admin script and I want to keep it as space-efficient as possible. What I want is for the ghostCommand function to be called and the unghostCommand function to be called. However I can't find a way to include a variable within a function name.
--Code snippet:
local commandsTble = {"*ghost","*unghost"}
local noAstCommandsTble = {}
for i = 1,#commandsTble do
table.insert(noAstCommandsTble,i,string.sub(commandsTble[i],2,string.len(commandsTble[i])))
end
for i = 1,#commandsTble do
if string.sub(msg,1,spaceLocation-1) == commandsTble[i] then
noAstCommandsTble[i]Command() ** -- Here is the problem (I am including a variable
-- inside of a function name)**
end
end
function ghostCommand()
print("Ghost command called")
end
function unghostCommand()
print("Unghost command called")
end
This does not work, however is there a way to make it work? I do not want to write an if statement for each command if I can help it. Thanks for reading!

6 comments
Please use a code block.
I don't know what you mean
You can use a module with the main loader... I'm not too experienced with modules or chat commands myself so my comment may be completely wrong. Though modules do make for cleaner, faster, more maintainable code.
Please put your code in a code block. The lua icon at the top of the question editor.
sorry, added code block
You might be interested in studying Roblox's "vote to kick" script's "matchPlayer" function, which will work with partial matches (ex "*gh" will match "*ghost" so long as there aren't multiple things that "*gh" could match)