Table.concat not working

Hey there! Right now, I’m trying to create an admin system in which all of the commands are in their own module script and are required by the MainModule.

At the current moment, it’s not working because I’m trying to concatenate the arguments table into its own thing so that data from it can be passed to the client, but it’s not working. Here’s the error I get when I try doing it:
image

MainModule:


Module Script:
image

When I try printing the arguments table it prints just that, so I have no idea what’s going on with the error. All help will be appreciated :slightly_smiling_face:

It looks like Arguments is in a dictionary. To retrieve its value, you should write
require(v)["Arguments"]
I can’t see your full module script so correct me if I’m mistaken.

1 Like

Still getting the same error. Thanks for trying to help me though!

Do you think you could show me the whole module script?

1 Like

I don’t think it would make a difference as what I’m showing you is pretty self explanatory. The MainModule is looping through the commands and then creating a value in a folder that will let the client + server view the commands. The Module Script here is the command, which should return the arguments, but table.concat isn’t working on it, even though I’ve checked that it returns.

Also, the MainModule is 190 lines of code long. If you still want to see it, though, I’ll send it to you via PM.

You shouldn’t require it 4 times like that, especially in a loop. It’s very inefficient. First thing I’d do to debug this is at the top of the for loop:

local mod = require(v)
print(mod)

Just to see what’s causing this.
I’d also keep mod afterwards so you don’t require it 4 times.

1 Like

Thank you so much for the idea! I’m surprised I didn’t think of it.

Modified code:

It still results in the same error as before, but for the print(req) it showed this:
image

Can you put the print before the table.concat? If it errors, you won’t see the one it errored on.

1 Like

Results in the exact same thing. This is in a for loop, by the way.

While it didn’t work when I did what you asked, I put it in a pcall w/ the name of script it errored on, and learned that I just did that one script wrong. Thank you so much for your help!

That’s one way to do it. It seems that you’re looping over a few different modules, and expecting them to have the same structure.

That error is telling me that one or more of the modules you’re looping over doesn’t have the “Arguments” key in its returned table.

You should implement checks to ensure the module returns what you expect it to, for example:

for ... in pairs(...) do
    local myModule = require(v)

    -- if the module doesn't return a table, skip to the next item in the loop
    if type(myModule) ~= "table" then
        continue
    end

    -- if the module contains a key, "Arguments," and it's a table...
    if type(myModule.Arguments) == "table" then
        local concatData = table.concat(myModule.Arguments, " | ")
        -- do stuff
    end
end
1 Like

This is already solved. Thank you so much for trying to help me, though!

1 Like

Just thought I’d provide you with an explanation as to why you were getting that error. Obviously if you found a way that works for you, stick with it!

1 Like

If you had posted that before I realized how to do it, it would’ve done the trick and would’ve shown me what I’ve done. Again, thank you so much for trying to help me!

1 Like