Table from ModuleScript returning nil

the error is happening in the server script, on the line "for _,v in pairs(roleList) do, the error is “invalid argument #1 to ‘pairs’ (table expected, got nil)”

Module Script

local module = {
	Owners = {
		{
			ChatColor = Color3.fromRGB(100, 103, 162),
			TagColor = Color3.fromRGB(43, 45, 112),
			Tag = "owner🔮",
			Users = {
				"noonewilleverknowthisuserohohohoho"
			}
		}
	}
}
return module

Script

local module = require(game.ReplicatedStorage.Utils.Roles)

local function isInRole(playerName, roleList)
	for _,v in pairs(roleList) do
		if v == playerName then
			return true
		end
	end
	return false
end

isInRole(player.Name, module.Owners.Users)

You have a table of tables, so you have to index it like this:

isInRole(player.Name, module.Owners[1].Users)

You could also just set up your module like this:

local module = {
	Owners = {
		ChatColor = Color3.fromRGB(100, 103, 162),
		TagColor = Color3.fromRGB(43, 45, 112),
		Tag = "owner🔮",
		Users = {
			"noonewilleverknowthisuserohohohoho"
		}
	}
}
return module

And your original script will work.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.