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

How can I get a folder of music to continuously be looped through?

I'm trying to write a simple script for looping through a folder that I have located in Workspace filled with music. Here's my current code:

music = game.Workspace.Music:GetChildren()

while true do
	for i, tune in pairs(music) do
		wait(1)
		tune:Play()
		wait(tune.TimeLength + 1)
	end
end

However, the music is not loaded on the server, it is loaded on the client. So when I attempt to get the music's TimeLength, it returns a 0. How can I get the desired effect in the most efficient way possible? Thanks in advance.

6 comments

0

Have you tried adding a 'repeat' loop to wait until the 'TimeLength' value is not congruent to 0? Probably not the best way, but it's as best I can think of atm. :)

1

@TheAlphaStigma That wouldn't help. TimeLength is always = to nil or 0 on the server. You have to check the sound's length on the client.

0

@Sporkyz Dang, I never knew that. :/

0

How is it on the client? It's on the server the music is located in Workspace. Alright well anyways is FE on? Where is this script located and what kind of script is it? FE = Filtering Enabled btw.

0

Sounds load locally, but the music is located in Workspace. FilteringEnabled is not on, and FE is not the problem. Again, it is because it loads locally that I'm having trouble.

0

There is a sound ended event. Call that when the sound ends and then start the next song. You don't even need a loop. Simply initiate the first song and the next song should begin as the last ended.

1 answer

Have you tried this?

sound1:Play()
sound1.Ended:connect(function()
	wait(1)
	sound2:Play()
end)
sound2.Ended:connect(function()
	wait(1)
	--Play next sound or restart sound loop by playing sound1 again.
end)

If you haven't tried this I recommend it.

2 comments

0

While I appreciate the event that I didn't know about, I think that this (while simpler than attempting to get the timelength of every song) ultimately faces the same issue. Since the song is loaded on the client, the ended event can't be detected from the server (I could be wrong), and so the script won't work.

0

Okay, good luck

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