I am making a system where I can open and close the ui. but the problem is that when you click on the ui it opens up and a tween plays you then can then click on other ui and the current ui or any other ui thats open will close with a tween. But when you click on the same ui the tween doesn’t play.
local Plr = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local OpenGUI = Plr.PlayerGui:WaitForChild("OpenGUI")
local ButtonGUI = script.Parent
local Switch = false
local GlobalSwitch = false
local TI = TweenInfo.new(
0.2,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut
)
function CloseOtherUI(SkipThisUI)
for _, UI in pairs(OpenGUI:GetChildren()) do
if UI == SkipThisUI then continue end
if UI:IsA("Frame") then
local TweenClose = TweenService:Create(UI:FindFirstChildOfClass("UIScale"),TI,{Scale = 0})
TweenClose:Play()
TweenClose.Completed:Connect(function()
UI.Visible = false
end)
end
end
end
for _, button in pairs(ButtonGUI:WaitForChild("Buttons"):GetChildren()) do
if button:IsA("TextButton") then
button.MouseButton1Click:Connect(function()
local UItoOpen = OpenGUI:FindFirstChild(button.Name)
UItoOpen:FindFirstChildOfClass("UIScale").Scale = 0
if UItoOpen then
TweenService:Create(UItoOpen:FindFirstChildOfClass("UIScale"),TI,{["Scale"] = 1}):Play()
if not GlobalSwitch then
CloseOtherUI(UItoOpen)
UItoOpen.Visible = not UItoOpen.Visible
Switch = not UItoOpen.Visible
print(Switch)
end
end
end)
end
end
MB if the video laggy but hopefully you understand what I mean