So, a while back I asked how I could make a limited stock shop.
The answer was HTTPService, so I’ve tried using a Trello API (basiclly I had a board on trello, which had a ITEMS category, which had cards in it, which were named like the items I wanted to sell, and the description of the card was the amount of stock left), but that didnt work quite well (the latency was pretty bad and if you spammed the buy button the stock would get a negative value)
So I’m asking this:
Do I need to make my own website for this to work?
How would I code the game to be able to communicate with the website?
If I need to make my own website, how would I do that?
The idea of a HTTPService oriented shop is cool, but is that really needed?
You can simply store the amount of items inside of a special inside of the datastore, adn each time someone buys that item, update the value by undecrementing it by 1.
How so?
This is much simpler than you’d expect. It’s just one int value being stored, and getting updated every once in a while. If you have problems perhaps use Datastore2
Okay, so I was about to say something about that “just 1 int value being saved” (since there would be more than 1 item), but I realised I could save all of the stock in a table.
The bigger question is - how (or when) would I save and load the data?
The data would be saved whenever someone buys the item, and for the loading, you just have to load it once each time the item is bought, store it in a variable, and use that variable for two things:
First, check if there are more items in stock before approving the purchase, meaning the loaded int value is > than 0. Then update the save value, by saving it again to the previous value - 1.
You could use a datastore to keep track of it. You would just have to save this every minute or 30 seconds instead of every purchase. As well, every few minutes you can check what the datastore has vs what you think you have on each server to fix for any count errors.
Let us know how it goes. I personally thought about doing something like this except it would be like an auction house. At the time I had my own server and planned on doing this with HTTPService but that was before the messaging service.
If you feel like you’ve got your answer make sure to mark the answer as a solution so others can quickly go to the solution and also know that your problem has been resolved.
I think I ran into another issue.
Everything works fine, but if you spam the buy button you can get up to 11 Mugs (Even though the max is 5)
Now, that seems like a simple fix, just add a debounce to the button, and yes I did do that, HOWEVER what if 2 people in different servers press the button at once when the stock is 1?