A small issue with a gamepass GUI

Hello, so basically I wanted to make a teleporter GUI just like games like Pet Simulator has, but when I went to test it instead of opening the frame it will tell me that I own the game pass and not opening the frame I just need help to fix this small issue because I can’t find my mistake.

The Script

NOTE: Don’t tell me about local sound because I fixed it.

I would check to make sure the user doesn’t own the gamepass already before prompting a purchase. You can make a variable “userOwnsPass” that uses UserOwnsPassAsync to check if they own the pass already. If they do then you can set the frame to be visible, if not prompt the purchase. Also question, does it make it through that last if statement? The frame is just not opening?

1 Like

Well, it’s a bit complicated but I don’t know why because when I went and tested it on studio it ask me I bought it for testing when I clicked it the frame show but when I leave close the frame and re-click the gui, it will ask me if I want to buy it once again. But in-game when I bought it, the game tells me that I already own it.

To fix that do what I just said to do, what you’re doing is constantly asking the user to buy the gamepass whenever they click the button. Use what I said above to check if the user already owns the gamepass.

1 Like

Ok, Thank you so much for helping me!

1 Like

@SkoobiDoobiDoo so basically it’s working but it will still tell the player that he owns the gamepass https://gyazo.com/5877217e6e86df7a546adafc7c542c9f

Can you show the new updated code please?

You could do it so if the player already owns it that it will delete the button (witch will let them buy it)
and replace it with a duplicate of the button but without the buy game pass and still have the UserOwnsPassAsync.

Screenshot_1139 Here is the new script

1 Like

Okay I see, you’re prompting the purchase first still. You want to see if the player owns the gamepass before prompting the purchase. I really wish I could write out an example but I’m on my phone currently. Before you do get the market service and prompt the purchase, you should have an if statement testing if the user owns the gamepass or not. So instead of having the if ask if he user already owns the gamepass within the prompt, out it before and love the prompt in that if statement.

1 Like

So this is how it ends up is this correct?

Yes, and then just make sure the frame gets set to visible after the purchase the gamepass too

Ok, thanks once again! I will definitely come and ask you if I ever going to need help if that doesn’t bother of course.

1 Like

A note that UserOwnsGamePassAsync is a memoise-based function and changes based on circumstances. If a user does not own a pass, false will be returned for that call as well as any call that happens 10 seconds after it. If a user does own a pass, true is cached and returned for the rest of the session on each subsequent call.

OP’s code can still prompt the user to purchase a pass if they click 10 seconds after clicking the button and if they buy the pass via the prompt.

1 Like

Oh wow I did not realize that, let me make sure I understood you. So if a user purchased the gamepass via the prompt and proceed to click the button again within 10 seconds it will still prompt them? What are some ways we can fix this? I was thinking a separate variable.

Yes.

Can’t be fixed because it’s not broken. The cache is handled on the backend. Reassigning the variable won’t override the memoisation behaviour.

Maybe store in a table the player’s name/id, followed by the id of the pass, whether it was a successful purchase (just in case) and possibly the time (tick), so it would look something like this

local ServerPurchaseHistory = {}

-- code & conditions etc
ServerPurchaseHistory[tostring(Player.UserId) .. "|" tostring(passId)] = {
    ["Player"] = Player, --Player object
    ["ID"] = PassId, -- why not? integer value
    ["Successful"] = SuccessfulPurchase or false, -- boolean val (incase nil)
    ["TimeBought"] = tick() -- yea that
}

Every second or so you could loop through and compare the current tick to TimeBought, check if that value is greater than or equal to 10.01 (just incase) then remove it from the table. Most of the values in the table arent needed but this is just an example (albeit a bad one) of how you could do (probably) do it.

1 Like

That would be too much for my small brain i’ve made it and now it’s working perfectly just working on the teleportation section now.

It was a way to create a possible solution to the 10 second delay between purchase time and register of purchase (for prompts) that colbert mentioned. It’s not necessary, but it would be nice for your players if you incorporate some method to work out whether they bought the gamepass so they don’t get multiple prompts, as that just leads to misunderstandings and them thinking they wasted/lost their robux.

yeah, I understand but the thing I am learning scripting and not a professional scripter so I stick by easy stuff so I could understand harder script better. You know slowly but surely.