How can I make a UI visible if the user owns the gamepass?

So basically I’ve been working on a button that when clicked, it promts a gamepass purchase. If they own the gamepass then they have access to the Team Change GUI. However, I’ve tried getting the TeamFrame to be visible when the player has the gamepass however it’s not working. I’m pretty sure I need to do something with the PlayerGui I’m just not sure how I do it. I’ve tried WaitForChild but I’m not sure what to do now. Here is the code

local Players = game:GetService("Players") -- Gets the service for players
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local Remote = ReplicatedStorage:WaitForChild("TeamChange")

local GamePassID = 11485810 
Remote.OnServerEvent:Connect(function(Player)  
	local OwnsPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassID) 

	if OwnsPass then -- User owns gamepass
		-- Goal is to make the TeamFrame UI visible 
	else
		MarketplaceService:PromptGamePassPurchase(Player,GamePassID)
	end
end)
1 Like

You can have the ScreenGui inside the server script and parent it to the PlayerGui if they own the gamepass.

Player.PlayerGui.[GamepassGui].Enabled = true
or
Player.PlayerGui[SomeGui].[Frame].Visible = true
or
Have a the UI inside of the script and do
script.[ScreenGui]:Clone().Parent = Player.PlayerGui

1 Like

Thanks for the help! This ended up fixing my issue,

		Player.PlayerGui.Gui.TeamFrame.Visible = true     
1 Like

Thanks for the quick response! I appreciate the help! I ended up finding the issue, have a great day and thanks again for the help!

1 Like