Help getting info from a table in a module script

Hi!
I currently have a list of moderators and such UserIds in a module script, and when they run a command I need to check if they are in that list, im not sure how to do that
Module script

local moderators = {
	411474387
}

return moderators

command executer

if command == "Kill" then
	--right here need to check if they are in the script 
	module.kill(target)
end

I would write a function that indexes the module using a for loop, searching for the respective player’s user ID; just comparing IDs to see if they match, and if so, execute the code you want:

local function PlayerHasPermission( player )
  for _, id in next, module do
    if id == player.UserId then return true end
  end

  return false
end
1 Like

im not sure if this would work, because I have different modules with tables, and this only goes through 1 of the,

local module = require(game:GetService("ReplicatedStorage").AdminUIModule)

local mods = require(game:GetService("ReplicatedStorage").AdminUIModule.Moderators)
local admins = require(game:GetService("ReplicatedStorage").AdminUIModule.Admins)
local owners = require(game:GetService("ReplicatedStorage").AdminUIModule.Owners)
function ValueExistsInTable(value, t)
	for i, v in pairs(t) do
		if v == value then
			return true
		end
	end
	
	return false
end

You could modify the function a bit and provide a table to index:

local function PlayerHasPermission( array, player )
  for _, id in next, array do
    if id == player.UserId then return true end
  end

  return false
end

if PlayerHasPermission(owners, player) or PlayerHasPermission(admins, player) or PlayerHasPermission(mods, player) then
  -- do something
end