I am creating a cafe system and basically a GUI guides you through the drink creation process. However, I only want one player to use a machine at a time, so I am wanting to create a queue. If you attempt to use the machine while a player is using it, it will tell you.
I just need to know how I would go about creating a queue (the best way to).
Could I create a folder and use values with player names as a queue? Or would that be something that you do in a script?
So if you just wanted it to only be used when open I suggest making a Bool Value that can be individually accessed per machine and enabling it when in use and disabling it when it is done, But if you wanted to make an actual queue to use it I would suggest making a table and as a player tries to use it add the player’s name to the end of that table so when you read the table the 1st value of that table is always the person at the top of the queue
You could represent a queue using a single table value (this would circumvent the need to instance various objects in order to represent your queue).
local Queue = {} --Queues follow a FIFO structure (first in, first out).
local function QueuePlayer(Player) --Call this to add an item to the queue.
if table.find(Queue, Player) then --If the player is already queued don't proceed.
return
end
table.insert(Queue, Player) --Append/insert the player at the end of the queue.
end
local function UnqueuePlayer(Player) --Call this to remove a specific item from the queue.
local QueuedPlayer = table.find(Queue, Player) --Find the queued player.
if QueuedPlayer then
table.remove(Queue, QueuedPlayer) --Remove the queued player.
end
end
local function UpdateQueue() --Call this to remove the first item from the queue.
if #Queue > 0 then --Check if queue has more than one item.
table.remove(Queue, 1) --Remove first item.
end
end
I’ve added comments which should help explain everything.