I’ve got the shop that resets every hour, but I’m stuck on the part where each item has only a limited amount, so only let’s say 100 people can buy it before it goes out of stock. Each time someone buys the item, the amount goes down, until there’s 0 (out of stock). I got it to basically work, but there are some cases like when there are is a new server, that server should copy the data if there already other servers, but if its the first server and it’s a new server, then it should either copy the data if the shop hasn’t reset yet, or create new data if the shop has already reset. I don’t know how to do this though, because the way I’m creating a global shop is using the Random.new(seed), with hours counting up each time. I’m using a while true loop to change it every hour, but I can’t figure out how to fix those cases. I’m currently trying to implement it with MemoryStoreService right now
Use datastores, when someone buys an item the count in the dataStore
goes down, when someone tries to buy it you first check if there are enough in stock.
If there alot of players in the game wont the queues fill up?
I suppose it could, you could also send a message to all servers that there is 0 left when the last one is taken, then you no longer have to use datastores and you could use a saved variable which resets when the shop gets restarted.
So basically you only say “sold out” once it is sold out, but if a server is filled and they are all trying to get how many are left then just tell them it at the same time and update the value every minute or so, until you receive the message that it is out of stockk.
add an argument that tells you wether there is data or not and also if it has been reset or not
I’m using a counter to see how many there are, so I want it to update
How would I change the reset argument
If relying on MemoryStoreService, that shouldn’t be possible as it can’t set datas, only add or remove them. try using MessagingService to see if the value has changed.
MemoryStoreService has SetASync: Though? I’m using it currently. Just the possible cases I want to watch out for
Whenever it resets just upload the data to the datastore, i dont do any storing stuff yet so i dont know how it looks, but i assume you should just upload the data whenever you reset
Yes, I do that, but I’m wondering whenever there are no players playing/no servers are up, the shop will still reset so it can’t update the data, but I want the new server to have the resetted data instead of copying the data, where it was last instead of the new copy
Whenever the server is closing use BindToClose and upload the current time, then when a server launches, use that time to calculate the time since the last reset and do whatever you need
I don’t think DatastoreService is the best idea.
MemoryStoreService is probably your best bet.
Try to make the resetting every hour something completely serverside, like watching os.time(). The limited amount can be done with MemoryStoreService.
Also it’s not needed now, but in the long run, you will probably have players with autoclickers spam buying it. I suggest only allowing a player to buy one item of limited stock like how Roblox does it.
You can use os.time() and Random.new() to fix this. No need to copy data from other servers. The most efficient solution is using Random.new()'s seed variable like so:
Random.new(os.date("%m%d%Y%H"))
→ This grabs the month, day, year and hour. This way you won’t run into repeating generations ever and it’s synced throughout all servers without needing any external way of sending or cloning data.
DO NOT use MemoryStoreService or DataStoreService for determining if the shop should be reset or not. Or if the shop should get items from a new server or not. When the server first starts, you can use that Random.new() ‘formula’ to instantly grab the new shop items.
Only use MemoryStoreService when dealing with limited stock.
Yes, that’s what I’ve done currently. I used Random.new(seed) which is the day, to make the random Items. What I’m using MemoryStoreService for is to get the stock amount, replicate the amount across all servers when it is bought, and make sure when it’s 0 no one is allowed to buy it anymore. My problem is that when the shop resets, it sets the data in the memorystore map to all the items and its stock amount. However, when there are no servers, when a new server is up, it won’t know that the shop has reset, so it will get the past data, instead of the new reset data, because there are no servers to reset that data.
You know what I could do I think, everytime the shop resets, I store the hour inside a queue, then when all servers are gone, check if hours are different, then set new data, else set the data to original data. This would work if there are no servers, or if new servers are joining while there are servers running.