I made this Roblox module named GUIHub. I first designed it to make it easier to manage frame navigation within a GUI. Instead of keeping it to myself, I decided to let others use it as well. Please note that this is my first module that I’m publishing and I may not be the most experienced scripter so please give any feedback, it would be very appreciated.
Model:
GuiHub.rbxm (2.0 KB)
Code:
local hub = {}
hub.__index = hub
function hub.new(mainGui, frames)
local self = setmetatable({}, hub)
self.Main = mainGui
self.Frames = frames
self.ActiveFrames = {}
for _, frame in pairs(self.Frames) do
if frame.Visible then
self.ActiveFrames[frame] = true
end
end
return self
end
function hub:OpenFrame(frameName, disableOthers)
local frame = self.Frames[frameName]
if not frame then warn("Frame not found for "..frameName or "[no name provided]") return end
if disableOthers then
for otherFrame, _ in pairs(self.ActiveFrames) do
if otherFrame ~= frame then
otherFrame.Visible = false
self.ActiveFrames[otherFrame] = nil
end
end
end
frame.Visible = true
self.ActiveFrames[frame] = true
end
function hub:CloseFrame(frameName)
local frame = self.Frames[frameName]
if not frame then warn("Frame not found for "..frameName) return end
frame.Visible = false
self.ActiveFrames[frame] = nil
end
function hub:CloseAllFrames()
for frame, _ in pairs(self.ActiveFrames) do
frame.Visible = false
self.ActiveFrames[frame] = nil
end
end
function hub:Enter()
self.Main.Enabled = true
end
function hub:Exit()
self:CloseAllFrames()
self.Main.Enabled = false
end
return hub
How to use:
After requiring the module, use .new(mainGUI, frames) make sure frames is a table of your desired frames.
Methods:
:OpenFrame(frameName, disableOthers) - Enables a specific frame, with the option to disable all others.
:CloseFrame(frameName) - Disables a specific frame.
:CloseAllFrames() - Disables all frames.
:Enter() - Enables the gui.
:Exit() - Disables the gui and all active frames.