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

Get Marketplace Service on Click?

local ItemID = script.Parent.Parent.ItemID.Value
local player = game.Players.LocalPlayer

function onClick(ItemID) 
m = game:GetService("MarketplaceService"):GetProductInfo(ItemID)
for i,v in pairs(m) do
	script.Parent.Parent.DIS_T.Text = (m['Name'])
	end
end 

onClick(ItemID)
script.Parent.MouseButton1Click:connect(onClick)

I'm using the script to get the name of an AssetID. When I click the button it does not work.

The output says:

18:32:12.670 - MarketplaceService:GetProductInfo() argument is not a valid assetId (supplied assetId was less than 0) 18:32:12.671 - Script 'Players.Player.PlayerGui.Catalog GUI.Frame.Search.GetInfo function', Line 2 - global GetInfo 18:32:12.672 - Script 'Players.Player.PlayerGui.Catalog GUI.Frame.Search.GetInfo function', Line 8 18:32:12.673 - Stack End 18:32:12.674 - MarketplaceService:GetProductInfo() argument is not a valid assetId (supplied assetId was less than 0) 18:32:12.675 - Script 'Players.Player.PlayerGui.Catalog GUI.Frame.Purchase.LocalScript', Line 5 - global onClick 18:32:12.676 - Script 'Players.Player.PlayerGui.Catalog GUI.Frame.Purchase.LocalScript', Line 11 18:32:12.677 - Stack End

This script changes the AssetID

function onClick() 
	wait (1)
	local itemID = script.Parent.Text
	if itemID ~= nil then
		script.Parent.Parent.GetButton.Image = "http://www.roblox.com/Thumbs/Asset.ashx?x=420&y=420&assetId="..itemID
		script.Parent.Parent.ItemID.Value = itemID
	end
end 

script.Parent.MouseButton1Click:connect(onClick)

2 answers

✓ Accepted answer
function onClick()
local ItemID = script.Parent.Parent.ItemID.Value
local ProductInformation = game:GetService("MarketPlaceService"):GetProductInfo(ItemID)
script.Parent.Parent.DIS_T.Text = ProductInformation.Name
end

script.Parent.MouseButton1Click:connect(onClick)

You were correct in using the marketplace service and getting the product info, however I am unsure as to why you used a loop?

When you GetProductInfo, it returns a table containing lots of information about the product, including the name.

I have also moved the variable declaration for ItemID inside the function, meaning it will refresh the value every time you click the button.

You can see everything that it returns by running this script in the command bar:

local ProductInformation = game:GetService("MarketPlaceService"):GetProductInfo(--[[ID]])

for Index,Value in pairs(ProductInformation) do
	print("['"..Index.."'] = "..Value..";")
end
local ItemID = script.Parent.Parent.ItemID.Value
local player = game.Players.LocalPlayer

function onClick(ItemID) 
m = game:GetService("MarketplaceService"):GetProductInfo(ItemID)
for i,v in pairs(m) do
    script.Parent.Parent.DIS_T.Text = (m['Name'])
    end
end 

onClick(ItemID)
script.Parent.MouseButton1Click:connect(onClick)

'm' is not defined in the script you have provided. Make sure that the variable 'm' is defined.

1 comment

0

'm' is defined.

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