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
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
local Songs = game.Workspace.Sounds:GetChildren()
while true do
local RandomSong = Songs[math.random(1, #Songs)]
RandomSong:Play()
RandomSong.Ended:Wait()
RandomSong:Stop()
end
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
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)