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

How would I print a audio name via audio ID in a sound Instance?

I'm not sure how to print out the audio name via sound Instance, I dunno if that's very clear but I thought i'd ask.

2 comments

0

Do you mean the audio name in the catalog?

0

Yes, I do.

3 answers

✓ Accepted answer

Here's how I've done it in the past

AudioName = game:GetService("MarketplaceService"):GetProductInfo(SONGIDHERE)
print(AudioName.Name)

You can retrieve the audio name using get product info.

The function GetProductInfo of the MarketplaceService allows us to get information about an asset or product.

Example:-

local mpServ = game:GetService('MarketplaceService')

local function getSongName(id)
	local res, data = pcall(function()
		return mpServ:GetProductInfo(id)
	end)
	
	-- check if the pcall was successful 
	if res and data.AssetTypeId == 3 then
		return data.Name
	end
	
	-- either an error with finding the asset or its not a song
	return false
end

-- test data
local songId = {
	-- a song id
	'142295308',
	-- not a song
	'193064098',
	'999999999999999999999999',
	-- another song
	'142281425'
}

-- run the tests
for i=1, #songId do
	print(getSongName(songId[i]))
end

The code above used pcall as the function GetProductInfo will error if the id is not found.

Once the data has successfully been retrieved we also should check what the asset is using the data passed back ie AssetTypeId. The Asset_type we need is audio so we need to compare this AssetTypeId with 3 then pass back the name of the asset.

I hope this helps, please comment if you do not understand how / why this code works.

print(THE SOUND.SoundId) --Idk exactly what you mean but here I tried.

1 comment

0

This would only print the sound Id he wants the name of the song from the id

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