Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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)
0
Gamepasses are no longer assets, use "game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.userId, 5794064)" instead ABK2017 406 — 5y
0
If it's a real old gamepass, make sure you have the correct # for it from it's URL ABK2017 406 — 5y
0
I fixed that obvious mistake (argh) Still doesn't seem to work though? Similaritea 58 — 5y
0
answered WideSteal321 773 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

Ad

Answer this question