How do I break the loop without getting any errors?

Error: break statement must be inside a loop

while true do
orderScreen.ClickDetector.MouseClick:Connect(function(player)
	print("1")
	if player:GetRankInGroup(settings.groupID) > settings.groupMinRank then
		print("2")
		if not player.PlayerGui:FindFirstChild("ServingScreen") then
			print("3")
				servingUI:Clone().Parent = player.PlayerGui
				break
				end)

Can you please indent your code correctly. I can’t read well.

Deepest apologies, basically my UI is only appearing once after clicking it, afterwards the UI doesn’t open anymore. Here is the full script.

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local eventsFolder = ReplicatedStorage.Events
local callNotificationEvent = eventsFolder:WaitForChild("CallNotificationEvent")

local cafeEventsFolder = ReplicatedStorage["Cafe System"]
local cafeEvent = cafeEventsFolder:WaitForChild("Cafe Event")

local settings = {
	groupID = 11390942,
	groupMinRank = 2
}

---------------------------------------CAFE SYSTEMS FOLDER AND SCREENS-----------------------------------------

local cafeSystemFolder = workspace["Cafe System"]
local screensFolder = cafeSystemFolder.Screens
local controlFolder = cafeSystemFolder.Control

local confirmScreen = screensFolder.ConfirmScreen
local collectScreen = screensFolder.CollectScreen
local orderScreen = screensFolder.OrderScreen

local servingUI = controlFolder.ServingScreen
local ConfirmUI = controlFolder.ConfirmScreen

-- FOR TESTING PURPOSES: workspace["Cafe System"].Control.ServingScreen:Clone().Parent = game.Players.iloveyoutube4474.PlayerGui

-------------------------------------------------Order Screen--------------------------------------------------
while true do
	orderScreen.ClickDetector.MouseClick:Connect(function(player)
		print("1")
		if player:GetRankInGroup(settings.groupID) > settings.groupMinRank then
			print("2")
			if not player.PlayerGui:FindFirstChild("ServingScreen") then
				print("3")
				servingUI:Clone().Parent = player.PlayerGui
------------------------------------------------Confirm Screen-------------------------------------------------

cafeEvent.OnServerEvent:Connect(function(player, request, item, name, employeeName)
	if request == "SendOrder" then
		if game.Players:FindFirstChild(name) then
			local ConfirmUIClone = ConfirmUI:Clone()
			ConfirmUIClone.Frame.Request.Text = "Would you like to accept your order by ["..tostring(player).."]?"
			ConfirmUIClone:SetAttribute("employeeName", tostring(player))
			ConfirmUIClone:SetAttribute("playerName", name)
			ConfirmUIClone:SetAttribute("items", item)
			ConfirmUIClone.Parent = game.Players:FindFirstChild(name).PlayerGui
		else
			callNotificationEvent:FireClient(
				player,
				"Error", -- Title Value
				tostring(name).." is not a valid player. Please Try Again.", -- Text Value
				"rbxassetid://0", -- Icon Value
				5 -- Duration Time
			)
		end
	elseif request == "OrderConfirmed" then
		local frames = confirmScreen.SurfaceGui.Frame
		local orderFolder = confirmScreen.OrderFolder

		local orderClone = orderFolder.Order:Clone()
		orderClone:SetAttribute("playerName", name)
		orderClone.ItemsTextBox.Text = item
		orderClone.NameTextBox.Text = name
		orderClone.Parent = frames.Orders
		
		
		local CollectFrames = collectScreen.SurfaceGui.Frame
		local ItemFolder = collectScreen.ItemFolder
		
		local ItemClone = ItemFolder.Order:Clone()
		ItemClone:SetAttribute("playerName", name)
		ItemClone.playerText.Text = name
		ItemClone.Text.Text = "MAKING"
		ItemClone.Parent = CollectFrames.Orders
		
		
		
		
		
		
		callNotificationEvent:FireClient(
			game.Players:FindFirstChild(employeeName),
			"Confirmed!", -- Title Value
			"Order has been sent to "..tostring(name), -- Text Value
			"rbxassetid://0", -- Icon Value
			5 -- Duration Time
		)
	elseif request == "OrderDenied" then
		callNotificationEvent:FireClient(
			game.Players:FindFirstChild(employeeName),
			"Error", -- Title Value
			tostring(player).." has denied the order. Try again later.", -- Text Value
			"rbxassetid://0", -- Icon Value
			5 -- Duration Time
		)
	end
end)

--------------------------------UNKNOWN AREA-------------------------------------------------------------------



--------------------------------UNKNOWN AREA-------------------------------------------------------------------



--------------------------------UNKNOWN AREA-------------------------------------------------------------------
1 Like

There is not a need to put the MouseClick event in the while loop.

1 Like

If so, the whole script will just break and the UI will not show up.

1 Like

That’s not how it works. You don’t have to put an event in a loop it will function every time you click it.

3 Likes