Ad
Log in to vote
0

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

Asked by 1 year ago

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.

0
Do you mean the audio name in the catalog? kingdom5 3007 — 1y
0
Yes, I do. Odiosus_Ancilla 34 — 1y

3 answers

Log in to vote
1
Answered by
Cuvette 242
1 year ago

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.

Ad
Log in to vote
1
Answered by
kingdom5 3007 Snack Break
1 year ago

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.

Log in to vote
0
Answered by
FiredDusk 1441
1 year ago
print(THE SOUND.SoundId) --Idk exactly what you mean but here I tried.
0
This would only print the sound Id he wants the name of the song from the id kingdom5 3007 — 1y

Answer this question



Ad