Script to automatically enable Certain billboards UI if a player owns a gamepass

I have secrets in my game and a gamepass to be able to know where they are with a billboard UI, this script SHOULD make the billboard UIs enabled if they own the gamepass, and keep it disabled (so dont do anything) if they dont. (only for them so client side)

this is located in a local script in StarterplayerGui

it doesnt work.


local gamepassId = 9248266  
local part = game.Workspace:WaitForChild("SecretUI")

local function onPlayerJoin(player)
	local hasGamepass = false
	pcall(function()
		hasGamepass = player:HasPass(gamepassId)
	end)
	if hasGamepass then
		for _, child in pairs(part:GetChildren()) do
			if child:IsA("BillboardGui") then
				child.Enabled = true
				if player:IsA("Player") then
					child.Enabled = player
				end
			end
		end
	end
end


game.Players.PlayerAdded:Connect(onPlayerJoin)

1 Like

Try using MarketplaceService:UserOwnsGamepassAsync(player, passId) to detect if the player owns the pass.

You should probably control the visibility client-side if it’s going to be different for each player.

2 Likes

so like as in client sided just put this in a local script, right?

as for the script, like this? it doesnt work



local MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 9248266  
local part = game.Workspace:WaitForChild("SecretUI")

local function onPlayerJoin(player)
	local hasGamepass = false
	pcall(function()
		hasGamepass = MarketplaceService:UserOwnsGamepassAsync(player.UserId, gamepassId)
	end)
	if hasGamepass then
		for _, child in pairs(part:GetChildren()) do
			if child:IsA("BillboardGui") then
				child.Enabled = true
				if player:IsA("Player") then
					child.Enabled = player
				end
			end
		end
	end
end


game.Players.PlayerAdded:Connect(onPlayerJoin)

1 Like

I think you need to use UserOwnsGamepassAsync server-side, and maybe use a RemoteEvent to tell the client if they own it. Also check those parameters because I can’t remember if it’s a player object or UserId.

1 Like