I have this random music but when the music ends, it overlaps with another song.
local SS = game:GetService("SoundService")
local Songs = SS:WaitForChild("Music"):GetChildren()
while task.wait(1) do
local Music = Songs[math.random(1, #Songs)]
Music.Playing = true
task.wait(1)
Music.Ended:Wait()
end
it happened because u put it ona while task.wait do, u need to use like this:
local SS = game:GetService("SoundService")
local Songs = SS:WaitForChild("Music"):GetChildren()
local isPlaying = false
while isPlaying = false do
local Music = Songs[math.random(1, #Songs)]
Music.Playing = true
isPlaying = true
Music.Ended:Wait()
isPlaying = false
end
corrected OP’s script and combined it with @How4rdy 's script
local SS = game:GetService("SoundService")
local Songs = SS:WaitForChild("Music"):GetChildren()
local function RandomSong()
while true do
if #Songs == 0 then return end
local MusicIndex = math.random(1, #Songs)
local Music = Songs[MusicIndex]
if Music:IsA("Sound") then
Music:Play()
Music.Ended:Wait()
end
end
end
RandomSong()