Purchase once script

So I was wondering if there was code so that when the player clicks the purchase button on the gamepass and they buy it the can only purchase it once

1 Like
local ClickDetector = script.Parent
local MarketPS = game:GetService("MarketPlaceService")
local GamePassId = 0 -->Gamepass Id here

ClickDetector.MouseClick:Connect(function(player)
   MarketPS:PromptGamePassPurchase(player, GamePassId)
end)

You can check, if a player owns a gamepass using

game:GetService("MarketplaceService"):UserOwnsGamePassAsync(UserId, passID)

Which will return a boolean value, so you can just say

local ownsGamePass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(UserId, passID)
if not ownsGamePass then
	game:GetService("MarketplaceService"):PromptGamePassPurchase(player, passID)
end

Read more about gamepasses here

A user can’t buy a gamepass twice, but if you don’t want the prompt to show, use this:

marketplaceService:UserOwnsGamepassAsync(userId, gamepassId)

To achieve this you can use the MarketPlaceService service
And then checking out this documentation:

nice thanks for the code but do i put it in server script service or somewhere in my gamepass code