How to make a "Already owned" ui?

Hi devs , i need your help today . I’m trying to make a script that when a player already own a gamepass , a “already ui” be visible.

Here is my script :


local GamepassId = 141279747
local HasPass = false
local MarketplaceService = game:GetService("MarketplaceService")

	script.Parent.MouseButton1Click:Connect(function(player)
	
	local success, message = pcall(function()
		HasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId)
	end)
	
	if HasPass == true then
		script.Parent.Owned.Visible = true
		print("Already has it")
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, GamepassId)
		HasPass = true
	end
end)

Someone can help me? tnks

Maybe this will work.

local MarketplaceService = game:GetService("MarketplaceService")
local Player = game:GetService("Players").LocalPlayer

local GamepassId = 141279747
local HasPass = false

local Button = script.Parent

local function UpdateHasPass()
	local success, message = pcall(function()
		HasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId)
	end)
	
	if success and HasPass then
		if HasPass == true then
			Button.Owned.Visible = true
		end
	end
end

Button.MouseButton1Click:Connect(function()
	if HasPass == true then
		Button.Owned.Visible = true
		print("Already has it")
	else
		MarketplaceService:PromptGamePassPurchase(Player, GamepassId)
	end
end)

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function()
	UpdateHasPass()
end)

UpdateHasPass()

The mousebutton1click function does not pass a player.

GuiButton.MouseButton1Click | Roblox Creator Documentation