Music System Script Looping

Hey! I’m trying to loop a script that gets a random sound in a Folder in the workspace and plays it. The problem is, it only plays one song and then stops and doesn’t continue playing the next song when the first one ends. I need help on making the script continue to work when the first song ends.

local Songs = game.Workspace.Sounds:GetChildren()

while true do
	local RandomSong = Songs[math.random(1, #Songs)]

	if RandomSong:IsA("Sound") then
		RandomSong:Play()
		RandomSong.Ended:Wait()
		RandomSong:Stop()
	end
end

Use for loop

local LocatonSongs = --Your folder location here
while task.wait() do
for _,songs in pairs(LocationSongs:GetChildren()) do
   if songs:IsA("Sound") then
      songs:Play()
      songs.Ended:Wait()
   end
end
end

This doesn’t loop it sadly :frowning:

Did you put your sound folder here?

local LocatonSongs = --Your folder location here

Yep (charrrrrrrrrrrrrrssssssss)

Is it on workspace? (charrrrrrr)

Yes, it is
I’ll attach a screenshot below

Screenshot of Folder in workspace:
image

try this

local Songs = game.Workspace.Sounds:GetChildren()

while true do
	local RandomSong = Songs[math.random(1, #Songs)]

	RandomSong:Play()
	RandomSong.Ended:Wait()
	RandomSong:Stop()
end

i think this should work

Still won’t loop, really weird…

try to check the volume of the sound and make sure its not 0 or something

Nope, its not… I’m really confused

I took one of my scripts:

while task.wait() do
	for _, u in pairs(script.Parent:GetChildren()) do
		if u:IsA("Sound") then
			u.Playing = true -- or u:Play()
			u.Ended:Wait()
		end
	end
end

Make sure the script is inside the folder.

is it on localscript or a script?

This still doesn’t work, sadly (charsss)

It’s on a script, should it be on a localscript?

Oh that is the problem! you should put it on a local script!

Thanks, this was the solution! To save me from creating a new post, I’m making a Music System GUI where a bar gets filled depending on how long the music has to end and the following script stopped working when I transferred it to a LocalScript:

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local MusicProgress = PlayerGui.MainUI.Music
local Songs = game.Workspace.Sounds
local SongsChildren = game.Workspace.Sounds:GetChildren()

RunService.RenderStepped:Connect(function()
	for _, Song in pairs(Songs:GetChildren()) do
		if Song:IsA("Sound") and Song.IsPlaying == true then
			local Progress = Song.TimePosition / Song.TimeLength
			MusicProgress.Progress.Filler.Size = UDim2.new(Progress, 0, 1, 0)
		end
	end
end)
1 Like