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.