Get asset type by asset id

I want to check if an asset exists and what’s its type if it does exist.
Here’s my code where I check is asset available:

local success, errormessage = pcall(game:GetService("MarketplaceService").GetProductInfo, game:GetService("MarketplaceService"), message[2])
if success then
					
end

I have no clue how to check is an asset a music. I have seen few pages including this page and this page and I still don’t know what’s the solution for the topic.
Please help me. Thanks.

2 Likes

Perhaps you’re looking for ProductInfo.AssetTypeId? For example,

if (ProductInfo.AssetTypeId == Enum.AssetType.Audio) then
    -- Code

GetProductInfo returns the AssetTypeId in the returned dictionary, which is an enum representing the type of asset returned. See the AssetType Enum Index for the enum names and values:

local success, dict = pcall(game:GetService("MarketplaceService").GetProductInfo, game:GetService("MarketplaceService"), message[2])
if success then
     if dict.AssetTypeId == Enum.AssetType.Audio then
         -- it's an audio, run code
     end
end

This works:

local success, dict = pcall(game:GetService("MarketplaceService").GetProductInfo, game:GetService("MarketplaceService"), message[2])
if success then
     if dict.AssetTypeId == 3 then
         -- it's an audio, run code
     end
end

Edit:
Here’s a list of asset type id’s: AssetType | Documentation - Roblox Creator Hub

7 Likes