Ad
Log in to vote
0

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

Asked by 1 month 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 2188 — 1mo
0
Yes, I do. Continence 34 — 1mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

3 answers

Log in to vote
1
Answered by
Cuvette 222
1 month 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 2188 Snack Break
1 month 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 1087
1 month 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 2188 — 1mo

Answer this question



Ad