Product info for bundles

Can someone help me with bundle functionality as well, since they don’t work with getproductinfo?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local function AsyncWrapper(asyncFunc, ...)
	local args = {...}
	local success, result = pcall(asyncFunc, table.unpack(args))
	if success then return result end
	warn("AsyncWrapper: "..result)
end

local NotifierEvent = Instance.new("RemoteEvent")
NotifierEvent.Name = "NotifierEvent"
NotifierEvent.Parent = ReplicatedStorage

MarketplaceService.PromptPurchaseFinished:Connect(function (player, assetId, wasPurchased)
	if not wasPurchased then return end
	print(tostring(player))
	print(tostring(assetId))
	print(tostring(wasPurchased))
	local assetInfo = AsyncWrapper(MarketplaceService.GetProductInfo, MarketplaceService, assetId)
	if assetInfo then
		NotifierEvent:FireAllClients(player.Name, assetInfo.Name, assetInfo.PriceInRobux)
	end
end)
1 Like

Yes they do, they have all default properties:

1 Like

How do I change to 4? What do I put?

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local function AsyncWrapper(asyncFunc, ...)
	local args = {...}
	local success, result = pcall(asyncFunc, table.unpack(args))
	if success then return result end
	warn("AsyncWrapper: "..result)
end

local NotifierEvent = Instance.new("RemoteEvent")
NotifierEvent.Name = "NotifierEvent"
NotifierEvent.Parent = ReplicatedStorage

MarketplaceService.PromptPurchaseFinished:Connect(function (player, assetId, wasPurchased)
	if not wasPurchased then return end
	print("Purchase finished for player: " .. tostring(player))
	print("Purchased assetId: " .. tostring(assetId))
	print("Was purchased: " .. tostring(wasPurchased))
	local assetInfo = AsyncWrapper(MarketplaceService.GetProductInfo, MarketplaceService, assetId)
	if assetInfo then
		if assetInfo.PriceInRobux then
			print("Price in Robux: " .. assetInfo.PriceInRobux)
		else
			print("Price in Robux: N/A")
		end
		NotifierEvent:FireAllClients(player.Name, assetInfo.Name, assetInfo.PriceInRobux)
		print("NotifierEvent fired with details:")
		print("Player: " .. player.Name)
		print("Asset Name: " .. assetInfo.Name)
	else
		print("Failed to retrieve asset info for assetId: " .. tostring(assetId))
	end
end)

MarketplaceService.PromptBundlePurchaseFinished:Connect(function (player, assetId, wasPurchased)
	if not wasPurchased then return end
	print("Bundle purchase finished for player: " .. tostring(player))
	print("Purchased bundle assetId: " .. tostring(assetId))
	print("Was purchased: " .. tostring(wasPurchased))
	local assetInfo = AsyncWrapper(MarketplaceService.GetProductInfo, MarketplaceService, assetId, 4) -- Assuming 4 is the correct infoType for bundles
	if assetInfo then
		if assetInfo.PriceInRobux then
			print("Price in Robux: " .. assetInfo.PriceInRobux)
		else
			print("Price in Robux: N/A")
		end
		NotifierEvent:FireAllClients(player.Name, assetInfo.Name, assetInfo.PriceInRobux)
		print("NotifierEvent fired with details:")
		print("Player: " .. player.Name)
		print("Bundle Name: " .. assetInfo.Name)
	else
		print("Failed to retrieve asset info for bundle assetId: " .. tostring(assetId))
	end
end)

The information for bundles thats returned from MarketplaceService:GetProductInfo is rather inconsistent. That might the problem here.

I recommend using AvatarEditorService:GetItemDetails to get much more consistent results AND more details too.

Adjust your script to implement AvatarEditorService:GetItemDetails instead of GetProductInfo, and see if that works :slight_smile:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local AvatarEditorService = game:GetService("AvatarEditorService")

local NotifierEvent = Instance.new("RemoteEvent")
NotifierEvent.Name = "NotifierEvent"
NotifierEvent.Parent = ReplicatedStorage

MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, wasPurchased)
	if not wasPurchased then return end
	print("Purchase finished for player: " .. tostring(player))
	print("Purchased assetId: " .. tostring(assetId))
	print("Was purchased: " .. tostring(wasPurchased))
	local assetInfo = MarketplaceService:GetProductInfo(assetId, Enum.InfoType.Asset)
	if assetInfo then
		if assetInfo.PriceInRobux then
			print("Price in Robux: " .. assetInfo.PriceInRobux)
		else
			print("Price in Robux: N/A")
		end
		NotifierEvent:FireAllClients(player.Name, assetInfo.Name, assetInfo.PriceInRobux)
		print("NotifierEvent fired with details:")
		print("Player: " .. player.Name)
		print("Asset Name: " .. assetInfo.Name)
	else
		print("Failed to retrieve asset info for assetId: " .. tostring(assetId))
	end

	-- Check if purchased item is a bundle
	local itemType = AvatarEditorService:GetItemDetails(assetId, Enum.AvatarItemType)
	if itemType and itemType.ItemType == Enum.AvatarItemType.Bundle then
		-- Handle bundle purchase
		local bundleName = itemType.Name
		local bundlePrice = itemType.PriceInRobux or "N/A"
		print("Bundle purchased: " .. bundleName)
		print("Price in Robux: " .. bundlePrice)
		NotifierEvent:FireAllClients(player.Name, bundleName, bundlePrice)
		print("NotifierEvent fired for bundle with details:")
		print("Player: " .. player.Name)
		print("Bundle Name: " .. bundleName)
	else
		print("Item purchased is not a bundle.")
	end
end)

I tried this but I don’t think it works :slightly_frowning_face:

Instaad of PriceInRobux, it should be Price as that’s what the price is defined as in the dictionary returned.

Additionally, why not just use MarketplaceService.PromptBundlePurchaseFinished for bundles instead of checking if a purchased asset is a bundle through MarketplaceService.PromptPurchaseFinished?

Yeah my bad, here’s the updated code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local AvatarEditorService = game:GetService("AvatarEditorService")

local function AsyncWrapper(asyncFunc, ...)
	local args = {...}
	local success, result = pcall(asyncFunc, table.unpack(args))
	if success then return result end
	warn("AsyncWrapper: "..result)
end

local NotifierEvent = Instance.new("RemoteEvent")
NotifierEvent.Name = "NotifierEvent"
NotifierEvent.Parent = ReplicatedStorage

MarketplaceService.PromptPurchaseFinished:Connect(function (player, assetId, wasPurchased)
	if not wasPurchased then return end
	print(tostring(player))
	print(tostring(assetId))
	print(tostring(wasPurchased))
	local assetInfo = AsyncWrapper(MarketplaceService.GetProductInfo, MarketplaceService, assetId)
	if assetInfo then
		NotifierEvent:FireAllClients(player.Name, assetInfo.Name, assetInfo.PriceInRobux)
	end
end)

MarketplaceService.PromptBundlePurchaseFinished:Connect(function(player, bundleId, wasPurchased)
	if not wasPurchased then return end
	print(tostring(player))
	print(tostring(bundleId))
	print(tostring(wasPurchased))
	local assetInfo = AvatarEditorService:GetItemDetails(bundleId, Enum.AvatarItemType.Bundle)
	if assetInfo then
		NotifierEvent:FireAllClients(player.Name, assetInfo.Name, assetInfo.Price)
	end
end)

It does work now :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.