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

Purchase Script Does Not Prompt Me To Purchase It?

I made a script so I don't have to update the game everyday to put up a new gift for the game to sell to players. I tested it myself (Deleted the gift and joined the game) but it did not prompt me to buy the free gift. Can someone help? [The gift is onsale]

game.Players.PlayerAdded:connect(function(plr)
	if not game.MarketplaceService:PlayerOwnsAsset(plr,582409069) then
		local passStats = game.MarketplaceService:GetProductInfo(582409069)
		if passStats.IsForSale then
			game.MarketplaceService:PromptPurchase(plr,582409069)
		end
	end
end)

EDIT : The gift is a decal asset. So someone from the ROBLOX Discord suggested that I should use print to find out where the code doesn't work. I found out that it was on the passStats.IsForSale. It returned to false, even though the asset was onsale. Please help.

2 answers

✓ Accepted answer

Decals can't be put up on sale (as in they can't be purchased using ROBUX), which is why IsForSale is returning false.

To fix this, you'll want to use IsPublicDomain instead of IsForSale since the decal can be added to the player's inventory without buying it.

game.Players.PlayerAdded:connect(function(plr)
    if not game.MarketplaceService:PlayerOwnsAsset(plr,582409069) then
        local passStats = game.MarketplaceService:GetProductInfo(582409069)
        if passStats.IsPublicDomain then --If the decal can be added to the user's inventory, prompt them to "purchase" it.
            game.MarketplaceService:PromptPurchase(plr,582409069)
        end
    end
end)

See here for more information.

If you created the item you must include "Enum.InfoType.Product" as your second argument for :GetProductInfo() as mentioned in the Wikipedia.

2 comments

0

Still doesn't work. It said an error "MarketplaceService.GetProductInfo() failed because rawProductInfo was empty"

0

The wiki said Enum.InfoType.Product is only used on Developer Products. This isn't a developer product but a decal (which is an asset)

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