Asset ID Price Display Error - "Attempt to concatenate string with nil" - Avatar Viewmodel Help

Hello, I’m running into an issue with displaying prices for certain avatars that are made on my avatarviewmodel.

Error:

  14:49:01.707  Players.TwinPlayzDev.PlayerGui.OutfitGUI.BuyFrame.ScrollingFrame.DonateGameClient:29: attempt to concatenate string with nil  -  Client - DonateGameClient:29
  14:49:01.707  Stack Begin  -  Studio
  14:49:01.707  Script 'Players.TwinPlayzDev.PlayerGui.OutfitGUI.BuyFrame.ScrollingFrame.DonateGameClient', Line 29  -  Studio - DonateGameClient:29
  14:49:01.707  Stack End  -  Studio

It’s odd because it does grab the majority of items, but some it doesn’t. I do believe that could be because some are offsale/limited edition. How can I go about fixing this? Or possibly avoiding the error. Do I need to add a pcall?

I also would like to know how it’s possible to grab the Total Cost of all the items? How could I go about this.

Here’s my current code for displaying the money portion -

local MarketPlaceService = game:GetService("MarketplaceService")
local ClickSound = script:WaitForChild("Click")
local TotalCost = script.Parent.Parent:WaitForChild("TotalCost")

for _, Child in pairs(script.Parent:GetChildren()) do
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
	end
end

script.Parent.ChildAdded:Connect(function(Child)
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
	end
end)
1 Like

For the total cost add a variable containing tbe costs added together:

local MarketPlaceService = game:GetService("MarketplaceService")
local ClickSound = script:WaitForChild("Click")
local TotalCost = script.Parent.Parent:WaitForChild("TotalCost")

local Total = 0 

for _, Child in pairs(script.Parent:GetChildren()) do
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
	end
end

script.Parent.ChildAdded:Connect(function(Child)
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
Total += Asset.PriceInRobux
	end
end)

For the other problem, make sure to check if the asset is for sale by using this:
IsForSale boolean Describes whether the asset is purchasable.

local MarketPlaceService = game:GetService("MarketplaceService")
local ClickSound = script:WaitForChild("Click")
local TotalCost = script.Parent.Parent:WaitForChild("TotalCost")

local Total = 0 

for _, Child in pairs(script.Parent:GetChildren()) do
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
If Asset.IsForSale then
		Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
else
Child:FindFirstChild("Cost").Text = ("Off sale")
Child.Buy.Visible = false
else
end
	end
end

script.Parent.ChildAdded:Connect(function(Child)
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
Total += Asset.PriceInRobux
	end
end)
2 Likes

This worked perfectly, although… The limited edition items aren’t getting calculated for some reason.

Updated Code:

local MarketPlaceService = game:GetService("MarketplaceService")
local ClickSound = script:WaitForChild("Click")
local TotalCost = script.Parent.Parent:WaitForChild("TotalCost")

local Total = 0 

for _, Child in pairs(script.Parent:GetChildren()) do
	
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		
		if Asset.IsForSale then
			Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
			Total += Asset.PriceInRobux
		else
			Child:FindFirstChild("Cost").Text = ("Off sale")
			Child.Buy.Visible = false
		end
		
	
		TotalCost.Text = ("Total Cost:$"..Total)
		
	end
end

script.Parent.ChildAdded:Connect(function(Child)
	
	if Child:IsA("Frame") and Child:FindFirstChild("Buy") then
		Child:WaitForChild("Buy").MouseButton1Click:Connect(function()
			MarketPlaceService:PromptPurchase(game.Players.LocalPlayer, Child.ProductIDVal.Value)
			ClickSound:Play()
		end)
	end
	
	if Child:IsA("Frame") and Child:FindFirstChild("Cost") then
		
		local ProductIDValue = Child:IsA("Frame") and Child:FindFirstChild("ProductIDVal").Value
		local Asset = MarketPlaceService:GetProductInfo(ProductIDValue)
		
		if Asset.IsForSale then
			Child:FindFirstChild("Cost").Text = ("$"..Asset.PriceInRobux)
			Total += Asset.PriceInRobux
		else
			Child:FindFirstChild("Cost").Text = ("Off sale")
			Child.Buy.Visible = false
		end
		
		TotalCost.Text = ("Total Cost:$"..Total)
		
	end
end)

I wonder if theirs a way to grab limited prices? Or does that require HTTPS:Services?

Seems like they are being marked as OffSale

image

Limited items are sold from resale, therefore you cannot get their price.

1 Like

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