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

I'm trying to find a song's length on Roblox. Is there anyway to find it?

I'm currently trying to create a music player, but I need the song's length. How would I get that? I've searched on the wiki and I really haven't found anything.

2 comments

0

The length of the sound is set in the Sound instance when loading the information is on the wiki page.

0

I will work on a script

1 answer

✓ Accepted answer

Once you load a song into your game, you can easily obtain it's 'song length' through a property of Sound.

As shown on the Roblox wiki Sound API page, there is a property called TimeLength:

TimeLength [readonly] The length of the sound in seconds. If the sound is not loaded, this value will be 0.

In script form, you'll have something similar to the bellow code:

local Sound = Instance.new("Sound", game.Workspace)
Sound.SoundId = ... -- Your content Id

print(Sound.TimeLenght) -- prints the length in seconds

Remember, TimeLength is readonly meaning you cannot change this value! If you want to play a song at a specific time, you would have to edit the TimePosition property.

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