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

Using GetProductInfo to check if Asset exists?

Say if I wanted to retrieve all possible audio id's using a ridiculously long for loop, and used the GetProductInfo of the MarketplaceService.

wait()
for idAsset = 156000000, 131000000, -1 do -- Rough approx. of newest sound id to oldest sound id.
local curId = game:GetService("MarketplaceService"):GetProductInfo(idAsset)
	if curId then -- This id exists.
		print(curId.Name) -- Print the name of the sound.
	end
end

However, when it executes for the first time:

MarketplaceService:getProductInfo() failed because rawProductInfo was empty.

I can't check whether it is nil (or otherwise empty)?

3 answers

wait()
for idAsset = 156000000, 131000000, -1 do -- Rough approx. of newest sound id to oldest sound id.
    local s, curId = pcall(function() return game:GetService("MarketplaceService"):GetProductInfo(idAsset) end)
    if s and curId then -- This id exists.
        print(curId.Name) -- Print the name of the sound.
    end
end

This should work. GetProductInfo errors if there is no asset with that ID. I would suggest adding waits if you experience latency.

1 comment

0

I've added a print statement after 'do' and it is returning an output every 1/5th of a second. Not sure if pcall has a delay when resulting in an error? The loop appears to run as if there is a wait() statement added.

The method :GetProductInfo() returns a dictionary table that you can search through. It will not give you the results you're looking for if you just check to see if it exists or not. You should be able to check to see if certain things in this library are nil if it would not exist, such as when it was created or it's creator.

Try using this:

 wait()
for idAsset = 156000000, 131000000, -1 do -- Rough approx. of newest sound id to oldest sound id.
local curId = game:GetService("MarketplaceService"):GetProductInfo(idAsset)
    if curId.Created ~= "null" then -- This id exists.
        print(curId.Name) -- Print the name of the sound.
    end
end

2 comments

0

That is optional. It is set 0 as default and this still returns the same error mentioned above.

0

Editted....

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