How to determine when a player buys a gamepass off the Roblox website?

Hi, topic title is pretty self-explanatory.

I was considering using the MarketplaceService.PromptGamePassPurchaseFinished event, however, this post invalidates it’s use for my situation. I really don’t want to make players rejoin a game if they decided to buy a gamepass off the website rather than in-game.

If anyone has any pointers, it’d be greatly appreciated!

1 Like

You could do a loop while they are in-game to keep checking if a player has a Gamepass or not. I don’t understand what you mean by the player having to rejoin if they bought the Gamepass off the website since they would likely not be in the game. If they were in the game, wouldn’t they rather buy it off of any in-game shop or system you used to prompt the player with the purchase instead of going to the website?

1 Like

The reason I want to implement this is for outlier cases (since it is a possibility). I want to make the player experience as smooth as possible if they decide for whatever reason to buy it off the website instead. A loop is not necessarily a bad idea, however I’d prefer an event connection instead (if it even exists).

I believe UserOwnsGamePassAsync() creates a loop that keeps checking if the player owns the Gamepass.

2 Likes

I’m pretty sure there isn’t anything that checks for it on the website itself. But since using a loop all the time may create minor lag, you could implement a button of sorts for the player to press for something like “Press this to refresh to see if you have the Gamepass” or something like that. This would prevent you having to create a loop and you just have to check only when the player wants you to check.

It’s rare that a player would buy a gamepass from the website while in the game, unless you never add an in-game prompt. You could check whether they own a gamepass on an interval if you want, otherwise just use PromptGamePassPurchaseFinished and check when they join.

1 Like

UserOwnsGamePassAsync() would be the easiest way to do it. As they stated, they do not want a player to re-join to get the Gamepass features.

1 Like

Won’t looping it cause unnecessary lag though? Sure it will probably not be a lot but still. You can still use it whenever the player wants the game to check if they own it, it would be a slightly better option imo.

However, checking on a loop is useless and a bad practice. Instead they should only be checking at key points in their game, like when the gamepass ownership status is needed for a calculation.

2 Likes

Thanks guys for the help! The general consensus suggests a loop is the only viable solution, not exactly ideal since it’s not instant, and will have to wait a couple seconds in between each iteration, but a couple second delay isn’t too bad. Sadly, there are no events I can use. :sob:

And yes, I’ve already implemented prompts and gamepass checks for when the player joins, I just wanted to see if there were any amazing solutions to this rare scenario.

Not using a loop would be worse, as it’s an extra step for the player. Having the server doing it would also be instant items, versus clicking a button, then checking 5+ extra lines of code before it does what it should.

If I find a better solution, I will message you! Otherwise have a fantastic day/night! :slight_smile:

1 Like

Sure, not using a loop would create a extra step for the player so I guess you could do a loop that checks probably every few seconds to minimize any server lag and make it more simpler for the player.

UserOwnsGamePassAsync caches the result. It doesn’t loop as someone posted earlier, it’s just a check with an endpoint whether or not the user owns a game pass.

Don’t use loops, figure out specific points in your experience where you can check for the ownership of game passes and update their status/apply the purchases to the player accordingly in those triggers. Of course, also be sure not to call it too frequently but enough so that the player can get to them quickly:

  • When a player first joins
  • When a round ends (for a round-based game)
  • When a player opens a shop window
  • When a player opens their inventory
  • When a player accomplishes a major achievement

No need to poll. Use event-driven systems to create triggers to check for unowned game passes and act accordingly based on the results. Skip checking owned game passes.

2 Likes

As I said, I belive it loops. I never said I know it does or that it does. And yes, it checks if the player has the Gamepass every so often. Also, UserOwnsGamePassAsync finds data which is not available because the information is still being requested like if the user has a Gamepass. So UserOwnsGamePassAsync is the best function to use for this.

You don’t have to “believe”: just read the documentation. It would explicitly say if it performs the check multiple times at various points in a session because that behaviour is important for a developer to be knowing about. If it’s available in documentation, no point in speculating.

I haven’t considered making my own triggers, it’s a great idea, I really didn’t want to settle for a loop! I’ll probably check gamepass owned statuses when players deploy (it’s an FPS game), since I need to apply the passive bonuses ASAP.

I mean the fact it returns a cached value throws a few spanners into the works when dealing with purchase outside of the game.

But thats neither here nor there. As mentioned above, its easier to poll if the user has it when it needs to be checked.

Loop-based code should be avoided if there’s a way to implement the same behaviour with events cough animation cycles cough

The speculation I made was because I am no advanced lua programmer. I am still learning it every day. As I stated though, UserOwnsGamePassAsync finds data that is not available, which would be the best option if you want to find data like that without trouble. For example a teleporter. You need to find the data fast to teleport the player when they purchase the pass, so you use UserOwnsGamePassAsync to find that data.