If Player Has Gamepass Show UI

I’m Trying To Make When A Player Has A Gamepass It Shows A UI

local MarketplaceService = game:GetService("MarketplaceService")
local UI  = game.StarterGui.TeleportUI

local gamePassID = 15973998  -- Change this to your game pass ID

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)

	if purchaseSuccess == true and purchasedPassID == gamePassID then
		print("true")
		UI.Enabled = true
	end
	
end

-- Connect "PromptGamePassPurchaseFinished" events to the "onPromptGamePassPurchaseFinished()" function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

This would make the UI show up when the user successfully purchases the gamepass but not when they rejoin.

You can use MarketplaceService | Roblox Creator Documentation in order to check if the player owns the gamepass, then enable the UI if they do.

UserOwnsGamePassAsync returns true if the player owns the gamepass.

You’re only setting the server’s GUI, not the actual Player GUI

Use a PlayerAdded event instead to fix this issue

local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = 15973998

game.Players.PlayerAdded:Connect(function(Player)
    local UI  = Player:WaitForChild("PlayerGui").TeleportUI
    if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassID)
	    UI.Enabled = true
    else
        MarketplaceService:PromptGamepassPurchase(Player, gamePassID)     
       
    MarketplaceService.PromptGamePassPurchaseFinished:Connect(PlayerWhoPurchased, CurrentPassID, WasPurchased)
             if WasPurchased == true and CurrentPassID == gamePassID then
                 UI.Enabled = true
             end     
        end)
    end
end)

Mobile y u do dis

Also I would recommend you to clone the gui to playergui from server because exploiters can easily make the gui visible if its on client. :wink:

Example:

local UI = game.ServerStorage.YourUI:Clone() --clone ui
local gamepassID = --your gamepass id
local MS = game:GetService("MarketPlaceService")

--now check if the player has the gamepass
game.Players.PlayerAdded:Connect(function(player) --player added event
if MS:UserOwnsGamePassAsync(player.UserId, gamepassID) then --check if player has gamepass
    UI.Parent = player.PlayerGui --set clone parent to playergui
    UI.Enabled = true --set gui enabled to true (optional)
      end
end)

Note: This is script inside ServerScriptService

3 Likes