So i made a Module which helps you code gui faster.
The Module is called GlobalUI.
NOTE: THIS WORKS ON THE CLIENT ONLY!
Heres and example on how to use it:
Instead of doing this:
local PlayerGui = Player.PlayerGui
local Frame = PlayerGui.Frame
local Frame2 = Frame.Frame2
local Label = Frame2.Label
Label.Text = "Test"
You can do this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Client = Players.LocalPlayer
local Shared = ReplicatedStorage.Shared
local Packages = Shared.Packages
local GlobalUI = require(Packages.GlobalUI)
local UI = GlobalUI:Load(Client) ::{ [string]: GuiObject }
UI.Label.Text = "Test"
If you are using this in another Script after Loading the UI, you can do:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Client = Players.LocalPlayer
local Shared = ReplicatedStorage.Shared
local Packages = Shared.Packages
local GlobalUI = require(Packages.GlobalUI)
local UI = GlobalUI:GetUI()
UI.Label.Text = "Test"
This is helpful if you want to access a GuiObject that is descendant of the UI and will take a lot of variables or code to modify.
This won’t work if you add a new GuiObject in the PlayerGui, but it’s really easy to fix by using another function from the Module.
Heres how to enable auto update for the UI:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Client = Players.LocalPlayer
local Shared = ReplicatedStorage.Shared
local Packages = Shared.Packages
local GlobalUI = require(Packages.GlobalUI)
local UI = GlobalUI:Load(Client) ::{ [string]: GuiObject }
local DescendantAdded = GlobalUI:InitiateDescendantAdded(Client, function(New)
UI = New
return
end)
Now if you add an instance in the PlayerGui, it will update the table that has all of the Guis stored in.
You can disconnect from this event if you do:
DescendantAdded:Disconnect()
Get the module Here.
If you have any issues make sure to comment, i will try to answer them.