Issues with concatenating string

I am trying to put them in a list, it works but then I get the error:
“attempt to concatenate string with function”

 for index, obj in pairs(Commands) do
        consoleLog(admin, index..". "..obj, false)
  end

It should say something like “1. Ban”, which it does but then I get that error.

Since the second parameter of consoleLog is looking for a string, you might have to make your iterations into a string variable.

local msg = tostring(index .. ". " .. obj) -- I added tostring() to ensure that it is indeed a string
consoleLog(admin, msg, false)

Still seems to error I even copied exactly what you put

What’s Commands? The error is basically saying your concating ". " with a function like if you had a function table.

local Commands = {
	function()
		--
	end,
}

Make sure you’re using the correct data by printing.

Commands is what module returns, it is just a list of names like

“Ban”, “Tempban”

Looks like obj might be a function. Make this change and check the output.

 for index, obj in pairs(Commands) do
    if type(index) ~= "string" or type(obj) ~= "string" then warn(type(index) .. ". " .. type(obj))
    else consoleLog(admin, index..". "..obj, false)
    end
  end
1 Like

I got this in my output

number. string (x3) 
string. function (x4)

Fiddled with it a little, found this issue Thanks

1 Like