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.