Greetings! I use CollectionService to control the UI Framework in my game. However, there is a little bug.
I need a task.wait(2)
in the code in order for it to properly work on all of the UI.
If you know of a better way of doing it, without the task.wait()
, that would be great!
Thanks in advance!
Working code:
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local StarterGui = game:GetService("StarterGui")
local Player = game:GetService("Players").LocalPlayer
task.wait(2) <--- This worries me
local UIKit = game:GetService("ReplicatedStorage").UIKit
local Topbars = CollectionService:GetTagged("Topbar")
local TweeningInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
for _, Topbar in pairs(Topbars) do
local ControlButtons = Topbar.ControlButtons
ControlButtons.Close.MouseEnter:Connect(function()
ControlButtons.Close.TextLabel.Visible = true
end)
ControlButtons.Close.MouseLeave:Connect(function()
ControlButtons.Close.TextLabel.Visible = false
end)
ControlButtons.Close.MouseButton1Click:Connect(function()
Player.PlayerGui.Launcher:SetAttribute("UIOpened", false)
Topbar.Parent:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.2, true)
Topbar.Parent:SetAttribute("Opened", false)
UIKit.MenuBar:Fire(true)
StarterGui:SetCore("TopbarEnabled", true)
task.wait(0.2)
Topbar.Parent.Visible = false
end)
print(Topbar.Parent.Name.. " is now closable.")
end