Game pass on touch script Error

Ok so, I have an issue. I made it to where when you touch the part the gamepass prompts you with a purchase ui. When the person buys the gamepass whenever they walk through the gamepass door its shows the the “You already own this item” message and it is really annoying. How do I stop this from happening.

here is the script

–Made by HB0MAX

local Players = game:GetService(“Players”)
local MarketplaceService = game:GetService(“MarketplaceService”)

local function onTouch(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
MarketplaceService:PromptGamePassPurchase(player, YOUR ID HERE) – gamepass ID


I’d imagine that if you owned the Gamepass, you can’t really prevent that from happening…

To stop the message from appearing though, you could use MarketPlaceService to detect whether or not the player owns that gamepass, then prompt the purchase accordingly.

1 Like

You need to detect if the player owns the gamepass already.

1 Like

the thing is, I do not know how

1 Like


still confusing. Its just showing me what it is. not how to use it

if MarketplaceService:UserOwnsGamePassAsync(UserId, GamepassId) then
    -- your code

Here is a more detailed explanation:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local PassId = -- your gamepass ID goes here

    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        if MarketplaceService:UserOwnsGamePassAsync(player.UserId, PassId) then
            -- user already owns the gamepass, do nothing
            -- user does not own the gamepass, rest of your code goes here

I think I fixed it! Thanks for your help man

No problem! If this was your solution, make sure to set it as solution so that others browsing the DevForum can easily find it :slight_smile:

Good luck with your game!

1 Like