Error "Attempted to call a table value"

When I try calling a table from a ModuleScript it gives me the “Attempted to call a table value” error, here is the part where It’s messing up:

for _,v in pairs(module.adminIds()) do

and here is the module part of the script:

--Script

local module = require(script:WaitForChild("Admins"))

for _,v in pairs(module.adminIds()) do
    print(v)
end

--ModuleScript

local Admins = {
	adminIds = {140800699}
}

return Admins

Is that the whole ModuleScript?

Remove the () after module.adminIds in this line:

for _,v in pairs(module.adminIds()) do

I thought the same thing at first, but he’s using a ModuleScript, so that somewhat makes sense to be there.

Correct.

JA*&#@JANAJDIOS

It has to be there because It’s calling it from a ModuleScript.

There’s your problem, you’re using the ModuleScript wrong.

local Admins = {}
local AdminTable = {
     adminIds = {}
}

function Admins.GetAdmin(x)
     if AdminTable[x] then
          return AdminTable[x]
     end
end

return Admins

Then use module.GetAdmin(data) and replace data with what you want to get.

It doesn’t, the () is what’s causing the error, edit that line to make it look like this:

for _,v in pairs(module.adminIds) do

2 Likes

That should actually work if the ModuleScript was used correctly though.

As Hellnickell said, remove the (). There’s no reason that should be there unless it’s calling a function and needs parameters.

Also you should have your module like this:

local Admins = {
	["adminIds"] = {140800699}
}

return Admins

or

local Admins = {}

Admins.adminIds = {140800699}

return Admins

(Idk why but not putting “[”" or “”]" always created problems, it was a while ago that I tested it though so :man_shrugging: )

Edit: I meant arguments, I always confuse the 2. Argument is the values you provide, parameters are the values the function uses that you’ve provided as arguments.

2 Likes