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)
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)
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.
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)