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.
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?
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.
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.
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.
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.
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.
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.
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.