Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you check if a user owns a gamepass and if not, prompt a purchase?

I'm simply wondering how to check if a player has a game pass and if not prompt a purchase. I tried making my own script, although I am not sure why it isn't working. Help would be very much appreciated!

wantedtrail = nil
script.Parent.MouseButton1Click:Connect(function()
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, 5794064) then
        wantedtrail = "RedTrail"
        workspace.Events.Trail:FireServer(wantedtrail)
    else
        game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 5794064)
    end
end)

4 comments

0

Gamepasses are no longer assets, use "game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.userId, 5794064)" instead

0

If it's a real old gamepass, make sure you have the correct # for it from it's URL

0

I fixed that obvious mistake (argh) Still doesn't seem to work though?

0

answered

1 answer

✓ Accepted answer

First of all, you never define player and second you use UserOwnsGamePassAsync for this, not UserOwnsAsset that is for things that are in the library/catalog.

Example code:

local player = game.Players.LocalPlayer
wantedtrail = nil

script.Parent.MouseButton1Click:Connect(function()
    if game:GetService("MarketplaceService"):PlayerOwnsGamePassAsync(player, 5794064) then
        wantedtrail = "RedTrail"
        workspace.Events.Trail:FireServer(wantedtrail)
    else
        game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 5794064)
    end
end)

Hope this helps!

If this does not work, remember use a local script

This discussion is preserved as it was. New answers, comments, and votes are closed.