Limited stock items using MemoryStoreService

With the new addition of MemoryStoreService allowing short term data to be added with the luxury of fast read and write ability, I’ve made a simple game that demonstrates the use of the service by making a system like roblox’s limited stock items.

Feel free to open the place up as it is uncopylocked: https://www.roblox.com/games/7548218764/Limited-Stock-Items

Here’s the rbxl file if needed: Roblox Item Stock System.rbxl (35.5 KB)

To explain what’s going on you must need to understand messaging service, datastore service, and memorystore service.

Pretty much what’s happening is an admin gets an admin panel that looks something like this:

The admin can then put the item name in the textbox, the stock, and the sellout timer in the text box. The item name will be the identifier for the item as we’ll be using it for the queue system from memory store service: image
After we’ve gotten our queue for the item we want to generate a limited quantity of we then call AddAsync on the MemoryStoreQueue object that’s been returned: image
We call this add async function as many times as there is stock of the item. For example; lets say the admin puts in a stock of 10, that means the for loop will iterate 10 times while incrementing the “serial” of the item based on the iteration that the AddAsync has gone through. The second parameter for AddAsync (The expiration) is how long the stock value will stay for. The max amount of time is 30 days, which is about which is around 2.592e+6 seconds (I googled it).

At this point, an issue has occurred. How will players know when an item has been released? That’s where datastore service comes in:


To sum up what’s happening in the photo above, I’ve made a Datastore called ItemStocks image
And preformed a GetAsync on it with the key “AllItems”. This datastore key value will return a table of ALL the items that were created by the admin with given information like ItemName, MaxStock, Timer, and OffsaleTimer. I then loop through those items to check if any of them went offsale or went out of stock and removed them to clean the table up. Once that’s completed, our new item will be inserted into the table and then we will set the new item table to the datastore key. This will help when new servers are created so that players are able to see currently listed items

To buy the item is simple


once the player gets notified through messaging service about the newly created item, they will be able to click on the gui button to call the remote event above which will get the queue for the specific item and preform a ReadAsync on it. The ReadAsync will take the next item serial off the queue giving the player whatever serial item was returned. This can be called as many times as possible until there’s no more items in the queue, we check for when no items in the queue exists by simply checking if a hash was returned.

The code for this is a little rushed and messy but I really want for people to see the possibilities of MemoryStoreService as it can be used to make amazing systems like this or even Matchmaking/Auction houses/User Markets.

28 Likes

I was actually thinking of doing this myself!

Nice work

Never knew about MemoryStoreService until now! Thanks to this post, I’ll definitely be using it in the future!

It recently was just released, that’s perhaps why.

All those limited sim trading games are about to get way more fun.