"MarketplaceService:getProductInfo()" failed because HTTP 400 (bad request)

Hello
I have an issue where I keep getting "MarketplaceService:getProductInfo()" failed because HTTP 400 (bad request) as an error or the TextLabel will want a string instead of a variable to change the text to. That is a problem as I am making a game for me and my friends to play on.

My plan was to get a PlaceID, and get info to teleport players to the game and display extra things like the game name or thumbnail (thumbnail and teleport already works, but not game name)
Any help is appreciated

Script
local TeleportService = game:GetService("TeleportService")
local MarketplaceService = game:GetService("MarketplaceService")

while wait(10) do
	local rnger = math.random(100000, 3000000000)
	local PlaceID = rnger
	
	local thumbnail = "https://assetgame.roblox.com/Game/Tools/ThumbnailAsset.ashx?aid="..PlaceID .."&fmt=png&wd=420&ht=420"
	local surfacegui = script.Parent.Parent.SurfaceGui
	local Placename = MarketplaceService:GetProductInfo(PlaceID)
	
	surfacegui.Thumbnail.Image = thumbnail
	surfacegui.PlaceName.Text = "Placename"
	
	script.Parent.MouseClick:Connect(function(player)
		TeleportService:Teleport(PlaceID, player)
	end)
end
3 Likes

The reason you’re likely getting that error is because that assetId doesn’t exist. With this method you’re doing, you’re likely to get that error quite often. What you could do is wrap that in a pcall() that way when it does error, it doesn’t break the script:

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

local GetInfo = function(id)

	local PlaceID = id

	local thumbnail = "https://assetgame.roblox.com/Game/Tools/ThumbnailAsset.ashx?aid="..PlaceID .."&fmt=png&wd=420&ht=420"
	local surfacegui = script.Parent.Parent.SurfaceGui
	local Placename = MarketplaceService:GetProductInfo(PlaceID)

	surfacegui.Thumbnail.Image = thumbnail
	surfacegui.PlaceName.Text = "Placename"
	return PlaceID
end

while wait(10) do
	local rnger = math.random(100000, 3000000000)
	local success, PlaceId = pcall(function()
		return GetInfo(rnger)
	end)

	if success then
		script.Parent.MouseClick:Connect(function(player)
			TeleportService:Teleport(PlaceId, player)
		end)
	else
		print('invalid')
	end
end
2 Likes

Didn’t work! Interval is empty, apparently. (line 18)

1 Like

Hello Furlicious,

You are likely getting a problem because the PlaceId doesn’t exist and/or because you simply don’t own the place.

1 Like

How did Super Place Roulette do it? They were able to get the place name.
Any how, I will be getting off for now. I might be able to see the new responses in approximately 8(ish) hours.

1 Like

In that case the problem is that the place doesn’t exist.

1 Like

Using external API call with HttpService I would imagine. That would require you to use a proxy and have understanding of how HttpService works.

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

local GetInfo = function(id)
	local PlaceID = id

	local thumbnail = "https://assetgame.roblox.com/Game/Tools/ThumbnailAsset.ashx?aid="..PlaceID .."&fmt=png&wd=420&ht=420"
	local surfacegui = script.Parent.Parent.SurfaceGui
	local Placename = MarketplaceService:GetProductInfo(PlaceID)

	surfacegui.Thumbnail.Image = thumbnail
	surfacegui.PlaceName.Text = "Placename"
	return PlaceID
end

local function GetRandomPlace()
	local rnger = math.random(100000, 3000000) -- don't set this too high as it'll cause math.random() to break
	local success, PlaceId = pcall(function()
		return GetInfo(rnger)
	end)

	if success then
		script.Parent.MouseClick:Connect(function(player)
			TeleportService:Teleport(PlaceId, player)
		end)
	else
		GetRandomPlace()
	end
end

while task.wait(10) do
	GetRandomPlace()
end
2 Likes

I would say it’s because when you definte ‘rnger’ you are using a maximum value of 3000000000, and no placeIds go anywhere near 3000000000. This means that a lot of the time you are generating a placeId of a place that doesn’t actually exist.

Try using this code:

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

while wait(10) do
	local rnger
	local PlaceID
    local success

    repeat
        rnger = math.random(100000, 900000)
	    PlaceID = rnger

        success = pcall(function()
            return MarketplaceService:GetProductInfo(PlaceID)
        end)
	    
	    task.wait()
    until success
	
	local thumbnail = "https://assetgame.roblox.com/Game/Tools/ThumbnailAsset.ashx?aid="..PlaceID .."&fmt=png&wd=420&ht=420"
	local surfacegui = script.Parent.Parent.SurfaceGui
	local Placename = MarketplaceService:GetProductInfo(PlaceID)
	
	surfacegui.Thumbnail.Image = thumbnail
	surfacegui.PlaceName.Text = "Placename"
	
	script.Parent.MouseClick:Connect(function(player)
		TeleportService:Teleport(PlaceID, player)
	end)
end
1 Like

It works, but the place name simply says “Placename” and that’s it.

That’s because you just have it set to setting the name as “Placename” and you’re not actually using your Placename variable + GetProductInfo() doesn’t return a string – it returns a dictionary. You’d have to change it to this:

First, change this line

local Placename = MarketplaceService:GetProductInfo(PlaceID)

to

local Info = MarketplaceService:GetProductInfo(PlaceID)

and then change this line

surfacegui.PlaceName.Text = "Placename"

to

surfacegui.PlaceName.Text = Info.Name

That should fix your issue. :slight_smile:

1 Like

Also, there is over 1 billion games and I think math.random doesn’t support that big of a number

Well, the largest value for an integer is 2,147,483,647 – so as long as you keep your random within that, you shouldn’t have any issues. :slight_smile:

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