Queue System Support

Hey everyone! I’m attempting to make a queue system for a game I’m working on, here are some snippets of my code below, for some reason, whenever the submitOrder button is pressed, it not only removes the first person from the queue, but also removes everyone else, please someone help, I’m not sure what’s going on.

Here is my server script:

game.ReplicatedStorage.OrderSubmitted.OnServerEvent:Connect(function(orderInfo, ordersTarget)
	if debounce == false then
		debounce = true

		if #orderQueue > 0 then
			local staffMember = orderQueue[1]
			print(staffMember)
			if staffMember then
				table.remove(orderQueue, 1)
				game.ReplicatedStorage.OrderRecieved:FireClient(staffMember)

				for i, remainingPlayer in ipairs(orderQueue) do
					game.ReplicatedStorage.UpdateQueuePosition:FireClient(remainingPlayer, i)
				end

				return staffMember
			end
		end

		print(orderQueue)

		local ticketNum = currentTicket + 1
		currentTicket = ticketNum

		local char = game.Workspace:FindFirstChild(ordersTarget)
		local ticketNumDisplay = script.TicketNumDisplay:Clone()
		ticketNumDisplay.Frame.Name1.Text = "Ticket #" .. ticketNum
		ticketNumDisplay.Parent = char:WaitForChild("Head")
		wait(2.5)
		debounce = false
	end
end)

And here’s my local script:

completeOrderButton.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		if items >= 1 then
			local ordersTarget = orderinfo["userName"]
			print(player, "-1")
			game.ReplicatedStorage.OrderSubmitted:FireServer(player, orderinfo, ordersTarget)
			maxedouttext.Visible = false
			finishorderbutton.Visible = false
			slideOut(orderInputFrame)
			wait(0.3)
			orderInputFrame.Visible = false
			coldDrinksB.BackgroundColor3 = Color3.new(0.913725, 0.752941, 0.54902)
			hotDrinksB.BackgroundColor3 = Color3.new(0.913725, 0.752941, 0.54902)
			pastriesB.BackgroundColor3 = Color3.new(0.913725, 0.752941, 0.54902)
			frame.Position = initialPosition
			maxItems = false
			orderinfo = {}
			activelyUsingRegister = false
			if items ~= 0 then
				items = 0

				local itemframes = {
					'item1',
					'item2',
					'item3',
				}
				for _,itemframe in ipairs(itemframes) do
					local actualItemFrame = oIOptionsFrame.Parent:FindFirstChild(itemframe)
					actualItemFrame.Text = ""

					local itemsdeletebutton = actualItemFrame:FindFirstChild('DeleteButton')
					if itemsdeletebutton then
						itemsdeletebutton:Destroy()
					end
				end
				return
			end
		else
			notiText.Text = "You must add atleast 1 item first, or use X to exit."
			notificationFrame.Visible = true
			notiSlideIn(notificationFrame)
			wait(3)
			notiSlideOut(notificationFrame)
			debounce = false
		end
		wait(1.7)
		debounce = false
	end
	return
end)

UpdateQueuePosition.OnClientEvent:Connect(function(newPosition)
	print('received!')
	lastPosition = newPosition
	queuePositionLabel.Text = "Your Position: " .. lastPosition
end)

game.ReplicatedStorage.OrderRecieved.OnClientEvent:Connect(function()
	print('fired')
	lastPosition = 0  -- Reset the last position when an order is received
	queuePositionLabel.Text = "Your Position: N/A"
	joinButton.Text = "Join Queue"
	joinButton.BackgroundColor3 = Color3.new(0.333333, 0.666667, 0)
	isInQueue = false
end)

It’s printing { [1] player2 } for the orderqueue like it’s supposed to but then it follows it up by printing {} for the orderqueue.

1 Like

Suggestion, you can just do " in OrderQueue" instead of “in ipairs(orderQueue)”, does the same thing. Also you messed up some arguments on your event calls, on the local script you include the player as the first argument but its unnecessary because remote events/functions always have the first argument it passes be the player that fired it for the OnServerEvent and OnServerInvoke Events/Functions. Similar thing on the server side, you didnt put the player as the first parameter which means that on the server “order info” is actually the player. Its also hard to tell whats wrong with order queue because there isnt too much given on how order queue is adding to itself etc. I assume order queue is an array of players, but other than that I cant guess more than that.

2 Likes

Thank you for the suggestions, I ended up getting it fixed, took several hours before I even made this post but I made it work (somehow), and yes you were correct regarding the array of players.

1 Like

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