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

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

Asked by 6 years ago

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.

0
The length of the sound is set in the Sound instance when loading the information is on the wiki page. User#5423 17 — 6y
0
I will work on a script GamingZacharyC 152 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Ad

Answer this question