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.
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.