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

Button prompts purchase even though I have the Gamepass?

Asked by 5 years ago

When I test my button, if it sees I own a certain asset it is supposed to teleport me somewhere. And even though I already own the gamepass specified in the script, it still prompts the purchase and doesn't teleport.

local gamepassID = 2657409
local assetID = 870836117
local debounce = false


local function OwnsShades(Hit)
if debounce == false then
    debounce = true

    local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if plr then
        if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,assetID) then
            print(plr.Name .. " owns the Midnight Shades")
            plr.MoveTo(workspace.Grass.Position)    
        else
            print(plr.Name .. " doesn't own the shades")
            game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamepassID)

        end
            wait(1)
            debounce = false
    end
end

end
script.Parent.Touched:Connect(OwnsShades)
0
For test purposes I think if you do it in studio, it will do a purchasing test as if you were testing in game transitions. Stephenthefox 94 — 5y
0
It doesn't work when i publish it either. GlobeHousee 50 — 5y

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

For gamepasses, you have to use UserOwnsGamePassAsync rather than PlayerOwnsAsset (which is only for items & clothing). So, for example:

local gamepassID = 2657409
local assetID = 870836117
local debounce = false


local function OwnsShades(Hit)
if debounce == false then
    debounce = true

    local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
    if plr then
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamepassID) then
            print(plr.Name .. " owns the gamepass")
            plr.MoveTo(workspace.Grass.Position)    
        else
            print(plr.Name .. " doesn't own the gamepass")
            game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamepassID)

        end
    end
    wait(1)
    debounce = false
end

end
script.Parent.Touched:Connect(OwnsShades)

You also needed to move the debounce outside the if plr then statement, otherwise if the object that hit was not a player, it would never be set back to false again. Also keep in mind UserOwnsGamePassAsync takes the player's UserId, rather than the player itself. You may also need to add a PromptPurchaseFinished for immediate feedback after the player has purchased the gamepass.

Ad

Answer this question