Hello, in my last post on this subject → Music Player With Progress Bar → I got it working but now at some point, the music stops playing and after a random amount of time, it plays again. Here is my server script:
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
Sorry if I made it sound confusing, ask me if you want me to explain it a bit easier.
local Sound1 = game.Workspace.Sound.Sound1
local Sound2 = game.Workspace.Sound.Sound2
local Sound3 = game.Workspace.Sound.Sound3
local Sound4 = game.Workspace.Sound.Sound4
while true do
Sound1:Play()
Sound1.Ended:Wait()
wait(5)
Sound2:Play()
Sound2.Ended:Wait()
wait(5)
Sound3:Play()
Sound3.Ended:Wait()
wait(5)
Sound4:Play()
Sound4.Ended:Wait()
wait(5)
end
Remember To Check The Sound ID’s Are correct.
The “wait(5)” Command, That mean when song done. How much wait for play next song.
You could try implementing a wait() after the song stops?
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()
wait(5)
end
end
If that doesn’t work, a different alternate would be to clone that specific Song Object, Play it, then Destroy it once it ends
I’ve had a problem like this before. Since I’m assuming this is playing right at the start of the game, it’s possible some of the sounds aren’t loaded. To make the script wait until the audio is loaded just do:
if not RandomSong.IsLoaded then
RandomSong.Loaded:Wait()
end
This, if the audio isn’t loaded, waits for the audio to load before playing it, otherwise it will go straight to playing it. Bare in mind that if the audio is already loaded then Loaded will not fire again, which is why we also check if the audio is loaded first.