Trying to make a admin command handler

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to make a simple admin command handler
  2. What is the issue? Include screenshots / videos if possible!
    It won’t work, I’ve tried just about everything but it just doesn’t send anything into the table
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked everywhere but can’t find any answers. I’ve tried different methods of inserting dictionaries into a table and it still won’t work.
local func = {}

local function create(...)
	func[#func+1] = {...}
end

create({
	["Name"] = "test",
	["Aliases"] = {"none"},
	["Function"] = function()
		print("Test functional!")
	end
})
print(unpack(func))
local functions = func[1]["Function"]
functions() -- Attempt to call a nil value

Would be very nice if anyone could help, thanks!

Let me elaborate your script line by line:

local func = {}

Here you’re assigning a variable to an empty table. So far so good.

local function create(...)
	func[#func+1] = {...}
end

You’re making a function which will insert a table of the parameters inside the table you created way up above.

create({
	["Name"] = "test",
	["Aliases"] = {"none"},
	["Function"] = function()
		print("Test functional!")
	end
})

Here is where it goes wrong. You are giving 1 parameter to the function, which is a dictionary.
Right now, your table “func” looks like this: {} and will now become:

{
    {
        {
            ["Name"] = ...(etc)
        }
    }
}

so to now call the function you want, you’d have to do:

local functions = func[1][1]["Function"]

or

funct[#func+1] = (...)

Then it would work.
tl;dr it doesn’t work because you forgot there’s another array you need to go through before going to the function you want to reference

1 Like

Thank you very much for the help! Now it works perfectly.

1 Like