Problem with GamepassAsync stuff

I created a GUI in which when the player clicks the open button, it either loads a frame asking them to purchase, or if they have it, open the MainFrame which I have yet to add stuff to. However, It isn’t working and I have spent a while trying to figure this out for myself, so I thought it’s time to ask the brilliant dev forum. Here is the attached file of which the GUI is located it.

Any help appreciated!

HelpNeeded.rbxl (22.3 KB)

1 Like

Replace the code inside the enabled LocalScript under the “Open” TextButton with this:

-- constants:
local GAME_PASS_ID = 5694417

-- services:
local playersService = game:GetService("Players")
local marketPlaceService = game:GetService("MarketplaceService")

-- Instances:
local localPlayer = playersService.LocalPlayer
local openButton = script.Parent
local photoOptionGui = openButton.Parent
local purchaseFrame = photoOptionGui.Purchase
local mainFrame = photoOptionGui.MainFrame


-- main:
openButton.Activated:Connect(function()
	-- get ownership status.
	local isSuccessful, isOwner = pcall(marketPlaceService.UserOwnsGamePassAsync, marketPlaceService, localPlayer, GAME_PASS_ID)
	if not isSuccessful then return end
	if isOwner then
		mainFrame.Visible = true
	else
		purchaseFrame.Visible = true
	end
end)

The code isn’t fully tested, as game pass ownership cannot be checked in an unpublished game. Let me know if something goes wrong.

I also noticed some small issues with the other code:

  • Global variables are used instead of local variables, which are faster to get.
  • RBXScriptSignal:connect, which is deprecated, is used instead of RBXScriptSignal:Connect.
  • GuiButton.MouseButton1Down is used instead of GuiButton.Activated, which works across all platforms.
  • The DataModel is indexed to get services instead of ServiceProvider:GetService, which uses class name rather than name and is encouraged by Roblox.

I press the button after making sure the code is correct (in a published place) but It doesn’t seem to be working either.

Try the new, edited code.

I did, I tested the code you replied with.

I just edited the code. Use the new, edited code.

Still isn’t working

What about it isn’t working?

I press the button after adding the code and it does nothing.

What part of the code is not working, though? The issue will be simple enough to isolate.

I don’t know

Do you have your place Filtering Enabled? If so, you’re gonna have to have to make a regular script that invokes the server and passes the player and the id of the gamepass. Here’s a snippet of something I’ve done in one of my games, very simple as it’s just an investment, but it has to be handled on the server with a RemoteFunction:
image

MAJOR EDIT

This is what your local script would look like if you have your IDs stored as IntValues. I just did this as a quick fix as it’s not going to exist forever, but it is functional!

Do you have output open? If you need to check go to VIEW on the top bar and then press Output
image
From there errors will appear on the bottom


You can use these errors to debug your code and figure out what’s going wrong.

1 Like

I always have output open but nothing is showing, as in errors

Okay, have you added any print statements to your script to check if it is executing? It may be placed in the wrong location or it may be yielding infinitely somewhere.

2 Likes

I’ll have to look it at later as I’m busy now. Thanks for reminding me as i normally add print(“”) to debug my scripts

When you’re using UserOwnsGamePassAsync you’re supposed to get the UserId, not the local player

2 Likes

I believe that every game is Filter Enabled running now regardless of whether the little checkbox is ticked or not. In his current script he isn’t using PromptPurchase so for now he can avoid using a Remote.

2 Likes