Difficulties Circumventing "PromptPassPurchaseFinished" Default Behavior

I’m currently creating a purchase handler and wanted to provide instantaneous feedback as soon as a pass was purchased. The issue I’m running into is the limitation of the event mentioned in the title, and that it only fires when the prompt window is closed. I want to be able to provide feedback as soon as a pass is purchased.

I know that this can be circumvented as I’ve seen first-hand that games such as Pls Donate provide the player with instantaneous feedback when a pass is purchased, even before the prompt is closed.

The MarketplaceService.PromptGamePassPurchaseFinished event passes three parameters:

  1. The Player in question.
  2. The GamepassId of the Gamepass.
  3. A bool to indicate whether the prompt was closed due to cancelling or purchasing.

So, the third parameter may help you in this case, by connecting the event to whatever you’re trying to do.

You may find the concerning documentation here:
MarketplaceService | Documentation - Roblox Creator Hub

Do note that the documentation suggests to check if the purchase was completed successfully after attempting to purchase by using the MarketplaceService:UserOwnsGamePassAsync() function, as the third parameter returns whether the Player attempted to purchase rather than the actual success of the operation.

Hope that helps.

2 Likes

@safeLast120, the issue is that he wants immediate feedback.

This event is the title of this thread, and his issue is that he wants an event to run as soon as the purchase is completed successfully, not when the prompt is closed.

I don’t know anything about this unfortunately, but I will look more into it if I have time and nobody else has helped in the future.

@sick_tr1cks , this part of my original response

covers that case: it needs to delay the rest of the code until a success confirmation, given by the MarketplaceService:UserOwnsGamePassAsync() function, as I posted earlier.

Again, he wants immediate feedback after a purchase is completed, not after a prompt is closed.

MarketplaceService.PromptGamePassPurchaseFinished only fires when the prompt itself is closed, successful or not.

For example, he wants the event to fire as soon as the prompt confirms the purchase went through, not after the player closes the prompt in it’s entirety.

Edit: It’s safe to assume he wants the event to fire like this in case somebody buys somebody else’s gamepass and rejoins before closing the prompt, granting the other player the robux but not running any server events (such as bonus coins)

Edit 2 + potential solution: I think what you could have meant to say is, when a prompt is initiated (detected by a custom event since theres no custom MPS event on starting pass prompts), there could be some sort of conditional loop to check if the gamepass is purchased via MarketplaceService:UserOwnsGamePassAsync(). Although there is a limit, it will still guarantee the server event firing if the player ends up purchasing the gamepass.

example:

local MPS = game:GetService("MarketplaceService")
local event1 = game.ReplicatedStorage:WaitForChild("event1") --could be a remote event but this is an an event signaling the opening of a prompt
local passPurchaseModule = require(game.ServerStorage.passPurchaseModule)

local function checkForGamepass(player, isInPrompt, gamepassId)

     while player ~= nil and isInPrompt.Value == true do
     task.wait(5) --wait whenever at the top, guarantees if the player purchases and quickly leaves they will still get the reward

     local bool = MPS:UserOwnsGamePassAsync(gamepassId)

     if bool == true then
          passPurchaseModule:RewardPlayer(player) --play server event or give player bonuses
          return true
          end

       end


return false
end

event1.Event:Connect(function(player, gamepassId) --should fire on opening of prompt

     local isInPrompt = player.isInPrompt --should have an attribute or boolValue to indicate if they are viewing a prompt
     local success = checkForGamepass(player, isInPrompt, gamepassId)


    if not success then
    print("player left or did not purchase the thing")
    end

end)

I apologize for the bad indentation or any coding mistakes, I am on mobile and I don’t currently have access to studio. This is merely sample code to hopefully help solve the problems for OP.

1 Like

Indeed, that’s what I meant to say.

Thanks for providing a better explanation, though.

1 Like

I’m glad we could agree on this, but unfortunately I think we’re both wrong :sweat:

On the MPS documentation you linked previously, in the UserOwnsGamepassAsync segment, it states how it actually caches the initial bool.

That means we could only check it once. Not a very good thing by Roblox, since I usually cache results myself via BoolValues.

So I actually don’t know how people like Haz3mn do it, if you could figure something out @safeLast120 i could learn something as well.

So clever, just connected the dots about the cache as well, haha.

The only viable thing I can think of at the moment is checking it once after some seconds (for tolerance to the operation) and leaving the rest to a prayer for a successful operation.

1 Like

exactly, I was thinking about 15 seconds, but I did a few test runs in Pls Donate and it fires immediately, even if you try to leave.

There is no yielding and it happens right after the prompt even tells you it’s complete.

I think he might actually run a remote event to his check gamepass function status after going into Roblox’s core GUI and detecting change on the gamepass purchase prompt itself…

1 Like

Just checked pls donate, their feedback isn’t instantaneous when you buy a pass. It only activates when you close the prompt

1 Like

Only products have this behaviour because of ProcessReceipt. Feedback upon closing the prompt as as immediate as you can get. Not sure why you would want any different though. What exactly are you trying to accomplish and why can you not simply wait until the prompt is closed so they can actually see the effects of their purchase?

2 Likes

Im pretty sure OP wants to avoid people disconnecting after purchasing a really expensive gamepass, obviously the purchase will still go through, but there may be some sort of server side code that wont run.

1 Like

Developers don’t necessarily need to account for disconnecting in their purchase code, Roblox already does. In the case of game passes and other purchases you can simply recheck the ownership upon rejoining and in the case of products you can stall the processing up to 3 days by returning NotProcessedYet. I can’t think of a valid use case where code needs to run immediately.

Would hope that OP can provide detailed insight as to why running code when the prompt closes is not sufficient and what they’re actually trying to do here.

1 Like

I think the only way to really do this is by creating one time use custom devproducts. So once it’s purchased, you get instant feedback and save the purchase in a datastore. Then check the datastore to see if the players purchased the pass already.

I prefer instantaneous feedback for a few reasons:

  • For example, a player donates and leaves the server without closing the prompt. In that case, this can lead to the failure of DataStores being updated and other events like visual effects and leaderboards not updating. Although the purchase is successful, the PromptGamePassPurchaseFinished event will not fire.

  • It’s mostly personal preference. Happy chemicals are released as soon as a purchase is made.

To address a possible solution regarding my first point, a system check could be implemented to update DataStores and other necessary elements when the player rejoins. However, this could become complicated if, for any reason, the player decides to never rejoin the game.

1 Like

You’re overthinking this. Why do you want to show a vfx to a player who leaves right after they make a purchase and don’t even bother closing the purchase pop up? The amount of people who fall into that edge case is basically zero. And for the datastore failure part, just get their gamepasses when they rejoin the game.

If it’s just a fun thing to do tho, I’d def recommend creating some devproducts that act like gamepasses because it’s basically the only way to accomplish this

You’ve unfortunately misunderstood the original problem OP has:

It’s not checking the gamepass itself; he’s making a pls donate game, so it doesn’t matter if the player owns the gamepass or not.

After a purchase, lets say you get a server message if you buy a gamepass from someone, however that server code only fires when the purchase prompt is closed. If the player disconnects before said prompt is closed, the server event will not run.

This means no happy chemicals for either player in the server and no anticipation for other players to donate as well. The actual Roblox transaction mentioned previously still goes through, like you said.

It’s a donation game. This means it’s other players, not the specific game’s gamepasses. A server message or bonus rewards would follow after a prompt, and if the gamepass is expensive and the player leaves, they won’t get any cool server event.

I don’t think Roblox allows 3rd party dev products, I could be wrong.

If you’re not going to help OP or actually understand the problem in the first place, I recommend you don’t reply to this thread anymore.

1 Like

For the second part, I’m not sure what you mean by third party dev products? What I mean by one time use devproducts is just regular devproducts but you can only buy them once like a gamepass. Because devproducts have a MarketplaceService.ProcessReceipt function which runs immediately after the player purchases the product. All you would have to do is connect the purchase to a datastore and check the datastore to see if a player has already purchased the “gamepass” (but it’s really a devproduct) and if they have, you don’t let them rebuy it.

What I’m referring to are OTHER PLAYERS making the devproducts, not OP. I’m 99% sure you cannot sell devproducts that don’t originate from the hosting game.

Again, this is a DONATION game, where players give robux to other players via gamepasses.

1 Like