Menu buttons bugging out when player exits another gui too fast

-- Local Script for opening the settings frame
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local SettingsButton = script.Parent
local Buttons = SettingsButton.Parent
local Menu = Buttons.Parent

local Frames = Menu:WaitForChild("Frames")
local Settings_Frame = Frames:WaitForChild("SettingsFrame")
local Exit_Settings_Button = Settings_Frame:WaitForChild("ExitButton")

local Sounds = Menu:WaitForChild("Sounds")
local AppearSound = Sounds:WaitForChild("AppearSound")

local Time = AppearSound.TimeLength
local AppearInfo = TweenInfo.new(Time, Enum.EasingStyle.Linear)
local debounce = false

SettingsButton.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true
	
	Settings_Frame.Visible = true
	AppearSound:Play()
	TweenService:Create(Settings_Frame, TweenInfo.new(Time, Enum.EasingStyle.Linear), {BackgroundTransparency = 0}):Play()
	
	for i, v in Settings_Frame:GetDescendants() do
		if v:IsA("Frame") then
			TweenService:Create(v, AppearInfo, {BackgroundTransparency = 0}):Play()
		elseif v:IsA("TextLabel") then
			TweenService:Create(v, AppearInfo, {TextTransparency = 0}):Play()
		elseif v:IsA("UIStroke") then
			TweenService:Create(v, AppearInfo, {Transparency = 0}):Play()
		elseif v:IsA("TextButton") then
			if v == Exit_Settings_Button then
				Exit_Settings_Button.Interactable = true
				TweenService:Create(Exit_Settings_Button, AppearInfo, {TextTransparency = 0}):Play()
				continue
			else
				v.Interactable = true
				TweenService:Create(v, AppearInfo, {BackgroundTransparency = 0}):Play()
				TweenService:Create(v, AppearInfo, {TextTransparency = 0}):Play()
			end
		else
			continue
		end
	end
	
	task.spawn(function()
		for i, Button in Buttons:GetChildren() do
			if not Button:IsA("TextButton") then continue end
			Button.Interactable = false
		end
	end)
	
	task.wait(3)
	debounce = false
end)
-- Local Script for exiting the Settings Frame
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local ExitButton = script.Parent
local Settings_Frame = ExitButton.Parent
local Frames = Settings_Frame.Parent

local Info_Frame = Frames:WaitForChild("InfoFrame")

local Menu = Info_Frame.Parent.Parent
local Buttons = Menu:WaitForChild("Buttons")

local Sounds = Menu:WaitForChild("Sounds")
local DisappearSound = Sounds:WaitForChild("DisappearSound")

local Time = DisappearSound.TimeLength
local Disappear_Info = TweenInfo.new(Time, Enum.EasingStyle.Linear)
local debounce = false

local function Disappear()
	for i, v in Settings_Frame:GetDescendants() do
		if v:IsA("Frame") then
			TweenService:Create(v, Disappear_Info, {BackgroundTransparency = 1}):Play()
		elseif v:IsA("TextLabel") then
			TweenService:Create(v, Disappear_Info, {TextTransparency = 1}):Play()
		elseif v:IsA("UIStroke") then
			TweenService:Create(v, Disappear_Info, {Transparency = 1}):Play()
		elseif v:IsA("TextButton") then
			if v == ExitButton then
				ExitButton.Interactable = false
				TweenService:Create(ExitButton, Disappear_Info, {TextTransparency = 1}):Play()
				continue
			else
				v.Interactable = false
				TweenService:Create(v, Disappear_Info, {BackgroundTransparency = 1}):Play()
				TweenService:Create(v, Disappear_Info, {TextTransparency = 1}):Play()
			end
		else
			continue
		end
	end
	
	task.wait(Time)
	Settings_Frame.Visible = false
end

ExitButton.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true
	
	DisappearSound:Play()
	TweenService:Create(Settings_Frame, Disappear_Info, {BackgroundTransparency = 1}):Play()
	
	task.spawn(Disappear)
	
	task.spawn(function()
		for i, Button in Buttons:GetChildren() do
			if not Button:IsA("TextButton") then continue end
			Button.Interactable = true
		end
	end)
	
	task.wait(3)
	debounce = false
end)


(Where everything is if needed)

My problem is that whenever I open the settings frame and close it really fast, the player will not be able to click on any of the menu buttons. It will just bug / glitch out and won’t work.

it might be because it takes time to make all the tweens. you should use a canvas group instead for Settings_Frame, and just tween GroupTransparency, it’s easier than changing the transparency of everything individually

Wait, I’ve never heard of CanvasGroup and I think I don’t think it will work because every instance has a different “transparency name” like TextLabels = TextTransparency and TextButton for BackgroundTransparency

CanvasGroup has a special property called GroupTransparency that affects the transparency of all its descendants

local RunService = game:GetService("RunService")
RunService.Stepped:Wait()

Can be useful for a bit more fine control in places.

if you don’t want to use a CanvasGroup, you could put all the tween stuff in a task.spawn() and that will probably work

I never knew that but I will try that :thinking:

The canvas group will simplify your code but it won’t fix the issue you are having. What i would suggest is you make these two scripts into one. so the debounce is shared. Right now what happens is when you open it, there is a debounce before you can open it again but not a debounce for when you close it so people can open and close it quickly

Oh okay. I will do that! :smiley: (Minimum characters)