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

Button prompts purchase even though I have the Gamepass?

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)

2 comments

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.

0

It doesn't work when i publish it either.

1 answer

✓ Accepted answer

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.

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