Sound not playing

I created a script to play a music list. However, after playing the first song, the second one does not play. Even when the prints suggest that they are playing.

Script (I will put what the second round prints)

local Sound = game:GetService("SoundService")

local SoundChild = Sound:GetChildren()

local function GetSong()
	local ran = math.random(1, #SoundChild)
	return SoundChild[ran]
end

local function PlaySong()
	print("Start") --Prints
	local Song = GetSong()
	print(Song.Name) --Prints
	Song:Play() 
	print(Song.Playing) --Prints
	print("Playing")
	Song.Ended:Wait()
	print("Ended")
	PlaySong()
end

PlaySong()

So what is wrong in the script?

Edit: I also tried this:

1 Like

Can you show us the children from SoundService?

I just tested your script with a couple audios in sound service and it works fine

Is the volume for your sounds at 0?

Sound_ (TwyPlasma Editing) - Roblox Studio 16_12_2020 10_31_47 pm (2)

Thats what I have for now

@Dogcraft_01 it is not at 0

@NevermindBuild, Strange, it does not work for me once it plays the second song

Where is the sound script located?

I just looped the function and it works have you tried this?

1 Like

It is under Sound Service as seen by the picture above

The script is in ServerScriptService

I tried it again, the second sound does not play

Edit: If you want, I can do a screen record of it

If it is possible a screen recording would be useful for me to see what you are doing yes :slight_smile:

try running it with a different audio in second place i believe the audio could be at fault

Is the audio taken down because if so this can lead to issues

You should check explorer for the audio printed out by the script to make sure it looks correct (sound above 0, playing set to true, maybe some other stuff).

Also, you should avoid recursion when you don’t need it. Recursion is just going to unnecessarily slow things down and cause problems in the long run. In this case, it’s infinite recursion which is even worse.

while true do
	print("Start") --Prints
	local Song = GetSong()
	print(Song.Name) --Prints
	Song:Play() 
	print(Song.Playing) --Prints
	print("Playing")
	Song.Ended:Wait()
	print("Ended")
end

I also ran into this same problem. The script is fine, the sound is playable but not when we test it. I guess it’s probably a studio bug.

Have you tried using SoundGroup?

Sorry for the late reply, here is the video/ video file

I had to trim it. So you only get the ending.

@Vulkarin I have changed to what you suggested and it does not work as well. And the volume is at 0.5 and playing was printed true

@orcazate The audio is still up and not taken down

@Nightmare4into96 for me, it does not work in both studio and in game

I also tried the following script but it does not work as well:

local Sound = game:GetService("SoundService")

local SoundChild = Sound.SongFolder:GetChildren()

local function GetSong()
	local ran = math.random(1, #SoundChild)
	return SoundChild[ran]
end

while true do
	local Song = GetSong()
	print(Song.Name)
	print("Starting")
	Song:Play()
	print("Playing")
	print(Song.Volume)
	if Song.Volume ~= 0.5 then
		Song.Volume = 0.5
	end
	print(Song.Volume)
	Song.Ended:Wait()
	print("Ended")	
	wait(2)
end

and

local Sound = game:GetService("SoundService")

local SoundIns = Sound.SoundPlayer

local SoundIds = {
	[1] = 214902446,
	[2] = 165065112,
	[3] = 142295308,
	[4] = 160442087
}

local function GetSong()
	local ran = math.random(1, #SoundIds)
	return SoundIds[ran]
end

while true do
	local id = GetSong()
	SoundIns.SoundId = "rbxassetid://"..id
	SoundIns:Play()
	print(id)
	print(SoundIns.IsPlaying)
	print(SoundIns.Volume)
	SoundIns.Ended:Wait()
	wait(5)
end

Try moving your sounds to some other location and not SoundService. Not entirely sure what the root problem is, but I feel it’s something got to do with SoundService. Does it matter where your sounds are located?

Not really, just only need to play it server wide but I that can be changed.

Edit: No idea why, but it works after moving the sounds that are going to be played into workspace.