Getting modules to be required by multiple scripts

I have my ClientManager, which manages basically everything inside the UI. It then requires each Module that controls it’s own section of the UI.

local infoManager = require(info.YY.InfoManager)

local mainManager = require(main.YY.MainManager)

However, from within these modules, I’m trying to return values back, so I don’t have to use the same functions over and over again. For example of infoManager

local infoManager = {}

local frame = script.Parent

local info = frame.Parent
local hud = info.Parent
local clientManager = require(hud.ClientManager)

local back = frame:WaitForChild('Back')

back.Activated:Connect(function()
	clientManager:Button(back, info)
end)

return infoManager

And back inside the ClientManager;

function clientManager:Button(button, frame)
	tween:New(button):Play()
	if button.Name == 'Back' then
		frame:TweenPosition(UDim2.new(0, 0, -1, 0), 'In', 'Back', 1, false)
		wait(1)
		main:TweenPosition(UDim2.new(0, 0, 0.5, 0), 'Out', 'Back', 1, false)
	elseif button.Name == 'Play' then
		frame:TweenPosition(UDim2.new(0, 0, 1.25, 0), 'In', 'Back', 1, false)
		wait(1)
		load:TweenPosition(UDim2.new(0, 0, 0.5, 0), 'Out', 'Back', 1, false)
	elseif button.Name == 'Info' then
		frame:TweenPosition(UDim2.new(0, 0, 1.25, 0), 'In', 'Back', 1, false)
		wait(1)
		info:TweenPosition(UDim2.new(0, 0, 0.4, 0), 'Out', 'Back', 1, false)
	end
end

I do not want this all done in the seperate modules, because then I’d need to have multiple tween modules (or else a ton of .Parent.Parent.Parent to get to the TweenModule)

Any tips would be greatly appreacited! :smiley:

1 Like

You could try parenting the TweenModule to PlayerGui and then simply just fetching it through require(game.Players.LocalPlayer.PlayerGui.TweenModule) or just having the modules for each section of the GUI just inside the ScreenGui so you don’t have to have a .Parent.Parent thing. Alternatively you could put the TweenModule in ReplicatedStorage and require it from there.

1 Like

You can put it all in one “Global” table and pass that table as argument (self in this case)

--// Main Script
local Global = {
	Modules = {Tween, ManagerA, ManagerB, ...} -- Table of modules
};
Global.Modules.Tween(Global, ...)
--// Tween
function Tween:Tween(...)
	-- Referencing other modules:
	local managerA = self.Modules.ManagerA
end
2 Likes