This code works to manage the menu I’ve created in my game. There are still more things I will be adding to it, but this is it so far. I don’t really like how I’ve organized it, and I really think it could be written much shorter and better.
I did actually end up putting all of my tweens into a table, but that’s only because they all need to run at once. Other than that, I haven’t really thought of any other improvements apart from like reorganizing it.
I hope this can become much more well written through the views of everyone who gives feedback.
Here’s the code block and file.
MainUIManager.lua (6.0 KB)
--Ramdoys
--Services
local rs = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local lighting = game:GetService("Lighting")
local players = game:GetService("Players")
local ts = game:GetService("TweenService")
local player = players.LocalPlayer
--Values
local uiOpened = false
local uiTimeOpened = false
local rotationValue = 90
--Gui Parts
local screenGUI = script.Parent
local blurBackground = screenGUI.BlurBackground
local selectionFrame = screenGUI.BlurBackground.ButtonSelectionFrame
local uiOpenCloseInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local uiOpen = ts:Create(selectionFrame,uiOpenCloseInfo,{Rotation=15})
local uiSelected = ts:Create(selectionFrame,uiOpenCloseInfo,{Rotation=0})
local descriptionLabel = blurBackground.ButtonSelectionFrame.Frame.ButtonDescription
--Tables
local selectionButtons = {
selectionFrame.Inventory,
selectionFrame.Settings,
selectionFrame.Statistics,
selectionFrame.Missions,
selectionFrame.Groups,
selectionFrame.Servers
}
local descriptions = {
"Equip items",
"Check stats",
"Missions and quests",
"Join parties and gangs",
"Change game stuff",
"Current and other servers"
}
local tweensF= {
TransUI1F = ts:Create(selectionButtons[1],uiOpenCloseInfo,{ImageTransparency=0}),
TransUI2F = ts:Create(selectionButtons[2],uiOpenCloseInfo,{ImageTransparency=0}),
TransUI3F = ts:Create(selectionButtons[3],uiOpenCloseInfo,{ImageTransparency=0}),
TransUI4F = ts:Create(selectionButtons[4],uiOpenCloseInfo,{ImageTransparency=0}),
TransUI5F = ts:Create(blurBackground,uiOpenCloseInfo,{BackgroundTransparency=0.4}),
TransUI6F = ts:Create(selectionFrame,uiOpenCloseInfo,{BackgroundTransparency=0.3}),
TransUI7F = ts:Create(selectionFrame.UIStroke,uiOpenCloseInfo,{Transparency=0}),
TransUI8F = ts:Create(screenGUI.Username,uiOpenCloseInfo,{TextTransparency=0}),
TransUI9F = ts:Create(blurBackground.TimeButton,uiOpenCloseInfo,{TextTransparency=0}),
TransUI10F = ts:Create(selectionButtons[5],uiOpenCloseInfo,{ImageTransparency=0}),
TransUI11F = ts:Create(selectionButtons[6],uiOpenCloseInfo,{ImageTransparency=0})
}
local tweensL = {
TransUI1L = ts:Create(selectionButtons[1],uiOpenCloseInfo,{ImageTransparency=1}),
TransUI2L = ts:Create(selectionButtons[2],uiOpenCloseInfo,{ImageTransparency=1}),
TransUI3L = ts:Create(selectionButtons[3],uiOpenCloseInfo,{ImageTransparency=1}),
TransUI4L = ts:Create(selectionButtons[4],uiOpenCloseInfo,{ImageTransparency=1}),
TransUI5L = ts:Create(blurBackground,uiOpenCloseInfo,{BackgroundTransparency=1}),
TransUI6L = ts:Create(selectionFrame,uiOpenCloseInfo,{BackgroundTransparency=1}),
TransUI7F = ts:Create(selectionFrame.UIStroke,uiOpenCloseInfo,{Transparency=1}),
TransUI8F = ts:Create(screenGUI.Username,uiOpenCloseInfo,{TextTransparency=1}),
TransUI9F = ts:Create(blurBackground.TimeButton,uiOpenCloseInfo,{TextTransparency=1}),
TransUI10F = ts:Create(selectionButtons[5],uiOpenCloseInfo,{ImageTransparency=1}),
TransUI11F = ts:Create(selectionButtons[6],uiOpenCloseInfo,{ImageTransparency=1})
}
--QuickSets
screenGUI.Username.Text = player.DisplayName.."(@"..player.Name..")"
screenGUI.Enabled = false
selectionFrame.Rotation = rotationValue
spawn(function()
local formattingString = "%I:%M %p"
local currentTime = os.date(formattingString)
local timeShowButton = blurBackground.TimeButton
timeShowButton.Text = currentTime
while task.wait(1) do
if os.date(formattingString) ~= currentTime then
currentTime = os.date(formattingString)
timeShowButton.Text = currentTime
end
end
end)
spawn(function()
local dayEndingName = "th"
local formattingString = " %X: %a, %B %d"
blurBackground.TimeInfo.InfoSec.Timezone.Text = os.date(" %Z")
local currentTime = os.date(formattingString)
while task.wait(1) do
if os.date(formattingString) ~= currentTime then
currentTime = os.date(formattingString)
blurBackground.TimeInfo.InfoSec.TimeExact.Text = currentTime
end
blurBackground.TimeInfo.InfoSec.ServerAge.Text = game:GetService("ReplicatedStorage").ServerValues.ServerAgeSTRING.Value
end
end)
--Functions
local TabCooldown = os.time()
local function TabUI(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and os.time() - TabCooldown >= 0.5 then
if input.KeyCode == Enum.KeyCode.Tab and uiOpened == false then
screenGUI.Enabled = true
for i, v in pairs(tweensF) do
v:Play()
end
uiOpen:Play()
lighting.Blur.Size = 20
blurBackground.TimeButton.Visible = true
task.wait(0.2)
uiOpened = true
elseif input.KeyCode == Enum.KeyCode.Tab and uiOpened == true then
for i, v in pairs(tweensL) do
v:Play()
end
lighting.Blur.Size = 0
blurBackground.TimeInfo.Visible = false
task.wait(0.2)
uiOpened = false
screenGUI.Enabled = false
selectionFrame.Rotation = rotationValue
selectionFrame.Position = UDim2.new(0.5, 0, 0.515, 0)
selectionFrame.Size = UDim2.new(0.2, 0, 2.2, 0)
for i, v in ipairs(selectionButtons) do
v.Visible = true
end
end
end
end
local function OpenTime()
for i, v in pairs(tweensL) do
v:Play()
end
blurBackground.TimeInfo.Visible = true
blurBackground.TimeButton.Visible = false
end
local function CloseTime()
for i, v in pairs(tweensF) do
v:Play()
end
blurBackground.TimeInfo.Visible = false
blurBackground.TimeButton.Visible = true
end
local function openStats()
selectionFrame:TweenPosition(UDim2.new(0.07,0,0.515,0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
selectionFrame:TweenSize(UDim2.new(.125,0,2.2,0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
uiSelected:Play()
for i, v in ipairs(selectionButtons) do
v.Visible = false
end
end
--Events
UIS.InputBegan:Connect(TabUI)
blurBackground.TimeButton.MouseButton1Click:Connect(OpenTime)
blurBackground.TimeInfo.Close.MouseButton1Click:Connect(CloseTime)
selectionFrame.Statistics.MouseButton1Click:Connect(openStats)