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.
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.
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:
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!
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.
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.