I'm trying to make a script that plays a random song from a folder i made in the sound service.
local sound = true
local CurrentSound = nil
while sound do
local Music = game:GetService("SoundService").MusicFolder:GetChildren() -- gets all of my sounds and puts them in a folder
local song = Music[math.random(1,#Music)] -- picks a random Song
song:Play() -- plays the sound
song.Ended:Wait(2) -- waits until the sound has ended and then it will wait for 2 seconds
-- should loop again and pick a random number and play it again but it doesn't?
end
It works when i play the game but after a song has played it just stops and doesn't play any more music just the first song it chooses

2 comments
Try calling :Stop() or clearing the variable Song.
YO i fixed it i still accepted the answer though because it helped me fix it the problem was that it was in sound service and sound doesn't play in the sound service so i just put it in workspace