I am trying to make a queueing system where when a player clicks a button they would be added to a queue using MemoryStoreService. Once the player presses Cancel they need to be removed from the Queue. I do not know how to go about this.
local function RemovePlayerFromQueue(Queue: MemoryStoreService, player: Player)
--What code needs to go here?
end
ReplicatedStorage.GuiEvents.LeaveQueue.OnServerEvent:Connect(RemovePlayerFromQueue)
i have finally found a solution but it may be a bit slow with big queues
local function RemovePlayerFromQueue(Queue: MemoryStoreQueue, player: Player)
local readSuccess, readResult = pcall(function()
return Queue:ReadAsync()
end)
if readSuccess then
-- Iterate through the items in the queue
for i, item in ipairs(readResult) do
-- Check if the item is the one you want to remove
if item == player.UserId then
-- Remove the item from the queue
local removeSuccess, removeError = pcall(function()
Queue:RemoveAsync(i)
end)
if not removeSuccess then
warn(removeError)
end
end
end
else
warn(readResult)
end
end
ReplicatedStorage.GuiEvents.LeaveQueue.OnServerEvent:Connect(RemovePlayerFromQueue)