Best way to convey product arguments

Not sure the title is written well but basically what I want to do is something like this.

I have a red gem and a blue gem and they both cost 30 robux.
Instead of me making a red gem product and a blue gem product I want to make one product that cost 30 robux and after bought it checks if the purchase was for the blue or the red gem.

Would the only way to do this be, when the product is done being purchased the promptpurchasefinished function invoked to the client to see which product they clicked on

Don’t re-use product IDs like this. It’s better to have separate product IDs for several reasons:

  • Players can see in their transaction history exactly what they bought. “Red Gem, Green Gem, Blue Gem” is much more helpful than seeing “Gem, Gem, Gem, Gem…” if they bought them all.
  • Your game would be tasked with remembering what “kind” of this product they bought. This implies using data stores if they bought something and it hasn’t been processed yet, and even that will have problems (what if they leave, and come back to a different server they didn’t buy it on? do we really know if they completed the purchase until we process the receipt? etc)

Sorry this is a bit of a non-answer, but this isn’t the road you wanna go down!

3 Likes

The reason im trying to do this is for a gifting product feature I was just using the gem thing as an example. Any tips for gifting

Ah okay. That’s a bit more complicated then, since it involves two players. Here’s how I’d go about doing this:

When the ProcessReceipt callback is called for the buyer, check if the recipient is in the server and in a state where they can receive gifts, eg, not teleporting away, leaving etc. If they are, then just grant them the gift immediately and return Enum.ProductPurchaseDecision.PurchaseGranted.

In the server the buyer is in cannot grant the purchase, you have several options. You should use the receipt ID as the gift ID, because it is guaranteed to be unique between purchases.

  1. Don’t grant the purchase (safe). Return Enum.ProductPurchaseDescision.NotProcessedYet so you don’t take people’s money without giving the gifts.
  2. Save the gift to a data store which is separate from typical player data (eg where the stuff in the gift would go). When a player joins a game, this data store should be checked for any gifts the player was given while offline or in a different server. Use UpdateAsync so you can provide a function that checks if the gift was already given (use the gift ID, see above). Only if the data store request was fulfilled successfully should you return PurchaseGranted, otherwise NotProcessedYet.
  3. Something you can try to do before #2 is using MessagingService to listen for gift-givings. More importantly, it’s not one-way: the recipient’s sever must respond to the purchaser’s that the gift was actually given to the player before it returns PurchaseGranted. Even for moderate sized games, you’ll have to do some special stuff to avoid hitting rate limits with regards to messages and topics, so I would stray away from doing this because even a veteran coder might screw this up.

Sorry, totally forgot to answer the basic question here because I was thinking big picture.

You’ll need the player’s client to submit the user ID of the recipient and also which gift, although that can just be a separate product. You can do this with a RemoteFunction, so the client gets acknowledgement that the server knows where their next gift will go. It’s probably a good idea to store information about a gift in data stores so if the game has to retry, it knows where to send things, but only after the server can confirm the gift isn’t deliverable by itself (eg, recipient is in another server).

tl;dr: Gift giving is hard. Roblox doesn’t have API for this that makes it easy. Sorry there’s no better answer :frowning:

1 Like