I have a gui text button that prompts a gamepass purchase but I want it to open a frame if the player owns the gamepass here is my script:
local plr = game.Players.LocalPlayer
local button = script.Parent
local MarkerPlaceService = game:GetService("MarketplaceService")
local gamepass_id = 39692796
script.Parent.MouseButton1Click:Connect(function()
MarkerPlaceService:PromptGamePassPurchase(plr,gamepass_id)
end)
local players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")
local passId = 2125638306
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if MPS:UserOwnsGamePassAsync(player.UserId,passId) then
local UI = script.OnlyGamepass:clone()
UI.Parent = player.PlayerGui
end
end)
end)
Explanation:
We use PlayerAdded event to fire whenever a player joins the game, we then want to use CharacterAdded [not always necessary], this will make sure to run a code whenever the chararacter reloads.
Now, make sure you have a UI under a script in ServerScriptService