im trying to make a really random game but it has a feature where players can buy rounds, so like the next round it will be the round they selected which the problem is that im not sure how to tell the server what round they selected.
Have you ever used
NumberValue
but when the player is buying its being bought from a local script, and the server script won’t see the numbervalue?
Keep track of what round they tried buying last. You can probably use a unique string for this.
This should be stored in a datastore so you can get it when they join another game while the devproduct hasn’t been handled yet.
Then within the ProcessReceipt callback, get the stored round, and start that round. You can assume this is the round they bought.
the rounds aren’t random and as i said when the player is buying the item, its being bought from the client, and you can’t just change the datastore or a stringvalue and expecting the server to just know.
Use remotes to send data between client and server.
I would only show a prompt when the server has successfully saved the selected round. So you’re sure it’s set correctly.
so how would the client know when the player bought the product?
I assume the client buys a product through a ui. You can detect it there in a localscripts.
The client doesn’t have to know if it was bought or not. The client only asks the server to save the selected round, and prompts purchase of a devproduct. The server handles the rest.
To be safe, only prompt the devproduct purchase once you’re sure the data is saved to the datastore, and don’t forget to add a debounce as there’s rate limits on saving data to datastores.
When the client wants to purchase the next round (such as clicking on a button), fire a RemoteEvent
to the server from the client that contains which round the client wants to pick. The server should then store the selected round somewhere, and prompt the purchase to the client.
To detect when the purchase has been successful, use ProcessReceipt
:
The server should then retrieve the stored round, and change the next round.