Hi,
I need help organizing my main menu module, there has to be a way to minimize this:
function MenuScreen.enableAsync()
local PlayerGui = Player:WaitForChild("PlayerGui")
MenuScreen.ScreenGui.Parent = PlayerGui
-- logo size animation
local MenuMusic = SoundService.Master.Background.Menu
local minSize = 0.9
local maxSize = 1.1
local smoothness = 0.05
MenuScreen._logoConnection = RunService.PreRender:Connect(function(deltaTimeRender: number)
local loudness = math.clamp(MenuMusic.PlaybackLoudness / 130, minSize, maxSize)
Logo:TweenSize(UDim2.fromScale(loudness, loudness), Enum.EasingDirection.In, Enum.EasingStyle.Linear, smoothness, true)
end)
-- seamless pattern
local x,y = Pattern.TileSize.X.Scale * 2, Pattern.TileSize.Y.Scale * 2
local speed = 5 -- higher = slower
TweenService:Create(
Pattern,
TweenInfo.new(speed,Enum.EasingStyle.Linear,Enum.EasingDirection.In,-1),
{Position = UDim2.new(-2*x,0,-2*y,0)}
):Play()
-- hover & functionality
local hover = SoundService.Master.Interface.Hover
local click = SoundService.Master.Interface.Click
local transition = require(script.Transition)
local playSound = require(ReplicatedStorage.Source.Util.playSound)
local tweenInfo = TweenInfo.new(
0.1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out
)
-- Main Menu
for _, frame in pairs(Background:GetChildren()) do
if not frame:IsA("Frame") then
continue
end
if not frame:FindFirstChildOfClass("TextButton") then
continue
end
local textButton = frame:FindFirstChildOfClass("TextButton") :: TextButton
local originalSize = frame.Size
textButton.MouseEnter:Connect(function(x: number, y: number)
local tween = TweenService:Create(frame, tweenInfo, {Size = UDim2.new(0.345,0,0.17,0)})
tween:Play()
playSound(hover,textButton)
end)
textButton.MouseLeave:Connect(function(textButton: number, y: number)
local tween = TweenService:Create(frame, tweenInfo, {Size = originalSize})
tween:Play()
end)
textButton.Activated:Connect(function(inputObject: InputObject, clickCount: number)
if Debounce then
return
end
local canvas = Background.Parent:FindFirstChild(textButton.Parent.Name)
if not canvas then
return
end
playSound(click,textButton)
transition.InAndOut(1)
task.spawn(function()
Debounce = true
task.wait(1)
Background.GroupTransparency = 1
canvas.GroupTransparency = 0
task.wait(1)
Debounce = false
end)
end)
end
local Statistics = MenuScreen.ScreenGui.Statistics
-- statistics
for _, frame in pairs(Statistics:GetChildren()) do
if not frame:IsA("Frame") then
continue
end
if not frame:FindFirstChildOfClass("TextButton") then
continue
end
local textButton = frame:FindFirstChildOfClass("TextButton") :: TextButton
textButton.Activated:Connect(function(inputObject: InputObject, clickCount: number)
if Debounce then
return
end
playSound(click,textButton)
if textButton.Name == "Close" then
return
end
transition.InAndOut(1)
task.spawn(function()
Debounce = true
task.wait(1)
Background.GroupTransparency = 0
Statistics.GroupTransparency = 1
task.wait(1)
Debounce = false
end)
end)
end
local Create = MenuScreen.ScreenGui.Create
for _, frame in pairs(Create:GetChildren()) do
if not frame:IsA("Frame") then
continue
end
if not frame:FindFirstChildOfClass("TextButton") then
continue
end
local textButton = frame:FindFirstChildOfClass("TextButton") :: TextButton
textButton.Activated:Connect(function(inputObject: InputObject, clickCount: number)
if Debounce then
return
end
playSound(click,textButton)
if textButton.Name == "Close" then
return
end
transition.InAndOut(1)
task.spawn(function()
Debounce = true
task.wait(1)
Background.GroupTransparency = 0
Create.GroupTransparency = 1
task.wait(1)
Debounce = false
end)
end)
end
local Join = MenuScreen.ScreenGui.Join
for _, frame in pairs(Join:GetChildren()) do
if not frame:IsA("Frame") then
continue
end
if not frame:FindFirstChildOfClass("TextButton") then
continue
end
local textButton = frame:FindFirstChildOfClass("TextButton") :: TextButton
textButton.Activated:Connect(function(inputObject: InputObject, clickCount: number)
if Debounce then
return
end
playSound(click,textButton)
if textButton.Name == "Close" then
return
end
transition.InAndOut(1)
task.spawn(function()
Debounce = true
task.wait(1)
Background.GroupTransparency = 0
Join.GroupTransparency = 1
task.wait(1)
Debounce = false
end)
end)
end
-- adjust strokes depending on viewport size
UIStrokeAdjuster:TagScreenGui(Background.Parent)
end