I have a Commands module script that has some commands with descriptions and functions. This is how it looks like:
local Commands = {
["cmds"] = {
desc = "Prints all the available commands.",
func = function(plr)
for _, cmd in pairs(script) do
end
end,
}
}
return Commands
Now apparentlyCommands cannot be accessed in the script, so I tried, as you can see, script. I don’t think this will work, so what can I do about this? Please don’t tell me I have to create another table…
pairs(script) gives the ‘expected table, got Instance error’ because you are supposed to use require() to import modules, but using require(script) would cause infinite recursion like making a function that calls itself
Instead of making it global, you should forward-declare it.
local Commands
Commands = {
["cmds"] = {
desc = "Prints all the available commands.",
func = function(plr)
for _, cmd in pairs(Commands) do
end
end,
}
}
return Commands