Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years 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? User#5423 17 — 7y
0
Yes, I do. Odiosus_Ancilla 34 — 7y

3 answers

Log in to vote
1
Answered by
Cuvette 246 Moderation Voter
7 years 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 7 years 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 1466 Moderation Voter
7 years 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 User#5423 17 — 7y

Answer this question