Limited stock shop with HTTPService

This is a tricky issue. How critical does it matter if a few extra ones are sold? Without constant access to something like a web server to handle all the buy requests, it may be hard to make this perfect.

You can send “Mug:3:1:5” and do what I said above and get the stocks by Table[3] and the max with Table[4]

I dont get what you mean

What I’m doing is I’m checking if the Stock value is higher than 0, give the item to the player and send a message to MessagingService to make the Stock value 1 lower.

Now, this works, but MessagingService takes too long to update the Stock value, so if you spam the buy button you can get twice the maximum amount.

Add a debounce and make it so the debounce only turns true if you receive an answer from MessagingService

That seems to work, but what about different servers?

What if 2 players from different servers press the buy button when the stock value is 1?

Since this is so hard to do, I came up with a different idea.

Instead of making a limited amount of items in the whole game, I will make it so random items get put in the shop with a random amount of stock. So every server will have different items and stock. Once shop is out of stock, it will restock after a set period of time.

Now I don’t know what answer to mark as solution lol

EDIT: The word “stock” was used WAYYY too many times here :rofl:

Actually, I just thought of something.
I send the new stock value through MessagingService (so if player buys while stock is 10 I send 9 through MS)

Would changing the send value from 9 to -1 and then substracting it change anything?

yeah sure that could work too i guess, anything works lol

Now this happens…
This is so annoying, I call PublishAsync ONCE when you click a TextButton and it says this every timebruh
Not only that, but the wait time is messed up too. Why is it even -2 billion lol

EDIT: Changed the name of the topic and it works now…

Ok so sending the amount that needs to be deducted rather than an amount the stock needs to be changed to works better, but still not perfect

Last time me and my firend spammed the button in 2 separaet servers, I had 5 and he had 6 (total of 11 even though the max is supposed to be 5)

Now I had 2 and my friend 4.
Pretty close, but I dont know what will happen when we do this with 3 separate servers