How to make a table reference itself?

Hello!

I am currently working on creating my game’s permission data which includes commands, arguments and the like. The problem is that if I want the table to reference itself, it will return an error like “Key Arguments not found in module”. The key arguments is what is containing each function to return the desired player(s).

Error and table:

Actual table:

module.Arguments = {
    ['all'] = function(playerName)
            return players:GetPlayers()
        end;
    ['random'] = function()
        local players = players:GetPlayers();
        return {players[math.random(1, #players)]}
    end;
    ['specificPlayer'] = function(playerName)
        for i,v in pairs(game.Players:GetPlayers()) do
            if v.Name == playerName then
                return {v}
            end
        end
    end;
    ['others'] = function(playerName)
        local players = module.Arguments.all
    end;
}

The table should be declared before assigning a self-reference.

module.Arguments = {
	['all'] = function(playerName)
		return players:GetPlayers()
	end;
	['random'] = function()
		local players = players:GetPlayers();
		return {players[math.random(1, #players)]}
	end;
	['specificPlayer'] = function(playerName)
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.Name == playerName then
				return {v}
			end
		end
	end;
}

module.Arguments.others = function(playerName)
	local players = module.Arguments.all
end
2 Likes