I’m currently making a cross-server block placement system using MemoryStoreQueues and MessagingService. Here’s how it should work:
- Place block
- Put it in the queue
- Check if the queue has x items (x = 5 for debugging)
- If item count reaches x, make a copy of the queue to be sent through MessagingService
- Clear the queue (only on the server the limit was reached on)
- Publish the queue to all servers using MessagingService
- Each server, upon the reception of the queue, loads the queue’s contents
Right now it seems like the queue does not clear consistently. I’m honestly pretty new to using MemoryStoreService so a lot of it has been trial and error. I’m assuming it’s something with the invisibility timeout, but I’m seriously lost as to what should be where, how much something should be etc. I just don’t want the duplicates to happen. I’ll paste the relevant code snippet along with a video that hopefully displays the issue as well as possible. Invisibility timeout is set to 30 seconds. Expiration for each item is set to 600 seconds.
Video (idk why it doesn’t embed):
External MediaPlacing:
local brickInfo = {}
brickInfo.BrickPosition = {brick.Position.X, brick.Position.Y, brick.Position.Z}
brickInfo.ColorOfBrick = tostring(brick.BrickColor)
brickInfo.BrickOwner = brick:FindFirstChild("Owner").Value
brickInfo.BrickDate = brick:FindFirstChild("Date").Value
brickInfo.BrickID = brick.Name
local success, err = pcall(function()
queue:AddAsync(brickInfo, EXPIRATION)
print("Added brick to queue: " .. brick.Name)
local succ, items = pcall(function()
return queue:ReadAsync(5, true, 0)
end)
if not succ then
warn("Failed to read queue:", items)
else
-- get items from queue and store them separately
-- clear queue items
-- send stored items to messagingservice
if items then
print("QUEUE FULL")
local QEUEUE = items
for _, it in pairs(items) do
print(it)
local removeSuccess, removeResult = pcall(function()
return queue:RemoveAsync(it)
end)
if removeSuccess then
print("Item successfully removed from the queue.")
else
warn("Failed to remove items from the queue:", removeResult)
end
end
messagingService:PublishAsync("SyncRequest", QEUEUE)
else
print("QUEUE NOT FULL")
end
end
end)
if not success then
warn("Failed to add brick to queue:", err)
end
Should I even be using queues for this anymore? I’ve tried hashmaps before, but I was very quickly hitting API request unit limits. What should I change? If something feels like it’s missing please let me know and I’ll answer back. Other than that I’d really appreciate any support here.