Button Issue: GUI Re-enabled and Click Detector Issues

Hello! I’m having an issue with the buttons. I don’t quite understand or maybe it’s just the fatigue from looking at so much code, but when I press the “button_HideGUI” button, the GUI hides and then reopens. This is incorrect. Also, when I press the buttons (button_HideGUI and button_yes_RequestOrder), I can’t use the click detector anymore afterward. What’s wrong, and how could I fix this issue?

As you can see in the video, after using the buttons a certain number of times (in this case, 3 times), it doesn’t let me re-enable the GUI. What’s wrong? :frowning:

server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShowGUIEvent = ReplicatedStorage:WaitForChild("showGUI_OrdersMenuEvent") -- RemoteEvent created in the client script

local ClickDetector = script.Parent.orderMenuClickDetector

-- Connect the MouseClick event of the ClickDetector
ClickDetector.MouseClick:Connect(function(player)
	-- Get the player's PlayerGui
	local PlayerGui = player:WaitForChild("PlayerGui")
	-- Find the specific GUI named "Order_Menu_UI" within the PlayerGui
	local SpecificGUI = PlayerGui:WaitForChild("Order_Menu_UI")

	-- Check if the specific GUI exists
	if SpecificGUI then
		-- Print a message indicating that the specific GUI was found
		print("Specific GUI found.")
		-- Enable the specific GUI to show it to the player
		SpecificGUI.Enabled = true

		-- Find the NoTextButton within the specific GUI
		local NoTextButton = SpecificGUI.Background.OrderFrame.NoTextButton

		-- Connect the MouseButton1Click event of the NoTextButton
		NoTextButton.MouseButton1Click:Connect(function()
			-- When the button is clicked, hide the specific GUI
			SpecificGUI.Enabled = false
			-- Print a message indicating that the GUI was hidden
			print("GUI hidden.")
			-- Fire an event to inform the client to re-enable the GUI
			ShowGUIEvent:FireClient(player)
		end)
	else
		-- If the specific GUI is not found, print a warning message
		warn("The specific GUI was not found.")
	end
end)

localscript:

local buttonsFolder = script.Parent
local button_HideGUI = script.Parent.Parent.OrderFrame.NoTextButton
local TotalCost_TextLabel = script.Parent.Parent.OrderFrame.TotalCostText
local button_yes_RequestOrder = script.Parent.Parent.OrderFrame.YesTextButton
local textOrdersNames = {
	script.Parent.Parent.OrderFrame.OrderName1Text,
	script.Parent.Parent.OrderFrame.OrderName2Text
}
local clickedButtons = {}
-- Define the prices for each button
local buttonPrices = {
	BurgerTextButton = 5,
	DonutTextButton = 3,
	FriesTextButton = 4,
	SliceOfCakeTextButton = 6,
	SodaTextButton = 2,
	WaterTextButton = 1
}
-- Function to update the order names based on the clicked button
local function updateOrderName(button, index)
	local orderNameText = textOrdersNames[index]
	if orderNameText then
		orderNameText.Text = button.Text
	end
end
-- Function to calculate the total price
local function calculateTotalPrice()
	local totalPrice = 0
	for _, clickedButton in ipairs(clickedButtons) do
		local price = buttonPrices[clickedButton.Name]
		totalPrice = totalPrice + price
	end
	return totalPrice
end
-- Connect each button's MouseButton1Click event to the updateOrderName function
for buttonName, button in pairs(buttonsFolder:GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			if #clickedButtons < 2 then
				table.insert(clickedButtons, button)
				updateOrderName(button, #clickedButtons)
				-- Update TotalCost_TextLabel with the total price
				TotalCost_TextLabel.Text = "Total Cost: $" .. calculateTotalPrice()
			end
		end)
	end
end

-- Connect the button_HideGUI's MouseButton1Click event to hide the GUI and reset the order names
button_HideGUI.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.PlayerGui.Order_Menu_UI.Enabled = false
	-- Reset the clickedButtons list
	clickedButtons = {}
	for _, orderNameText in ipairs(textOrdersNames) do
		orderNameText.Text = "..."
	end
	-- Reset the TotalCost_TextLabel
	TotalCost_TextLabel.Text = "Total Cost: $0"
end)

-- Connect the button_yes_RequestOrder's MouseButton1Click event to hide the current GUI and show another GUI
button_yes_RequestOrder.MouseButton1Click:Connect(function()
	-- Hide the current GUI
	game.Players.LocalPlayer.PlayerGui.Order_Menu_UI.Enabled = false
	-- Show another GUI (replace "loading_order_sent" with the name of the other GUI)
	game.Players.LocalPlayer.PlayerGui.loading_order_sent.Enabled = true
	wait(3)
	game.Players.LocalPlayer.PlayerGui.loading_order_sent.Enabled = false

	-- Reset the clickedButtons list, order names, and total cost label inside the other GUI's event handler
	clickedButtons = {}
	for _, orderNameText in ipairs(textOrdersNames) do
		orderNameText.Text = "..."
	end
	-- Reset the TotalCost_TextLabel
	TotalCost_TextLabel.Text = "Total Cost: $0"
end)

-- Connect to the event fired from the server to re-enable the GUI
game:GetService("ReplicatedStorage").showGUI_OrdersMenuEvent.OnClientEvent:Connect(function()
	-- Re-enable the GUI
	game.Players.LocalPlayer.PlayerGui.Order_Menu_UI.Enabled = true
end)

It looks like you’re hiding the GUI and then telling the client to show it again.

By the way, there’s no need to put a comment for every single line of code, it should
usually explain for itself

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.