How would I play every audio in a folder

I want a local script to go through every audio in a folder and play it (a soundtrack) but I don’t know how to do that. I also have a option for the audio to be turned off.

1 Like

Well you can loop through all of the instances in the folder, make sure that their audio, and then play them.

for an example,

for i, v in pairs(game.Workspace:WaitForChild("Soundtrack"):GetChildren()) do -- ipairs loop to get each individual audio instance
       if v.ClassName == "Audio" then -- Double checking if the object/instance is an Audio
         v:Play() -- Plays the Audio
    end
end

And if you want to make it so it gets turned off, you can loop through it again but turn it off this time.’’

Hope this helps

hey! this is the code I have right now.



while script.Parent.ConfigValues.Music.Value == true do
	
	for i, song in pairs(script.Music:GetChildren()) do
		song:Play()
		song.Ended:Wait()
	end
	
end

I want it to detect if the music option is turned on or off while the sound is playing but the wait is preventing that.
@NubblyFry

1 Like
while script.Parent.ConfigValues.Music.Value == true do
	
	for i, song in pairs(script.Music:GetChildren()) do
                 if MusicOption = true then
                  -- play song
                else
                   song:Stop()
              end
	end
end

Try something like this

1 Like

no cooldown. It crashed my script

it kept on playing the song without cooldown and crashed the script. @StarJ3M

Thats because you didn’t add a cooldown

try adding a task.wait() at the beggining after

while true do
 -- add here
end
1 Like

hey I added a task.wait(1) after the while true and it played 1 second and kept on repeating it.

once I pressed stop it didn’t play again after I turned it back on

Can You show me the script?


yup

local MusicOption = script.Parent.ConfigValues.Music

while script.Parent.ConfigValues.Music.Value == true do
task.wait(1)
	for i, song in pairs(script.Music:GetChildren()) do
		if MusicOption.Value == true and song:IsA("Sound") then
			song:Play()
			
		else
			song:Stop()
		end
	end
end

I think its because the script thinks that when you say else, that you mean that your trying to saying if the value doesn’t equal true and that the song isn’t a sound

So you should do a else if instead and check if its false AND if its a sound.

1 Like

that did absolutely nothing… I think its the wait but idk

u just need make a loop then play it

for i, v in pairs(workspace.Part:GetChildren()) do -- all folder in part
	if v:IsA("Sound") then -- check it sound or not
		v:Play() -- play it
	end
end

dont forget click solution if it work*

2 Likes