How can I detect that someone has bought my gamepass

Please help me, how can I detect that a player has bought my gamepass id in script
Script :

local productId =  1233982215
local player = game.Players.LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:connect(function() 
	print('Click was detected! GG!')
	game:GetService("MarketplaceService"):PromptGamePassPurchase(player, productId)

end)

Use PromptGamePassPurchaseFinished.

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, id, purchased)
    if purchased and id == productId then
        --purchased
    end
end)
local productId =  1233982215
local player = game.Players.LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:connect(function() 
	print('Click was detected! GG!')
	--game:GetService("MarketplaceService"):PromptGamePassPurchase(player, productId)
  MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, id, purchased)
		if purchased and id == productId then
			print("lo tienes :D")
		end
	end)

end)

I already bought the gamepass but it does not detect the print, what happens?
is local script btw

Try this

local productId =  1233982215
local player = game.Players.LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, id, purchased)
	if purchased and id == productId then
		print("lo tienes :D")
	end
end)

script.Parent.MouseButton1Click:connect(function() 
	print('Click was detected! GG!')
	game:GetService("MarketplaceService"):PromptGamePassPurchase(player, productId)
end)


I already have the gamepass purchased, but nothing comes out in the output just
print(‘Click was detected! GG!’)
but why
doesn’t it come out
print(“lo tienes :D”)
?
sorry i am using translator

I want you to teleport when you buy it and if you bought it to teleport you to a place

I mean

  1. The player comes
  2. Buy the game pass
  3. click the gamepass button again and it’s done tp

Enter the game again click the button
and it is done tp because he already has it bought

It doesn’t print since the purchase failed. Maybe remaking the gamepass will fix it?

I want that when you buy it you can teleport whenever you want and press the button,sorry for my grammar I use translator x2

It doesn’t print because the PromptGamePassPurchaseFinished has to be a server script.