Help me with background music playlist code?

hello, my background music code won’t work. Is it outdated? Does it have to be rewritten from the start? Is it messy and spaghetti?

Please help me, i’d be glad.

BTW the output says the SoundId is not a part of workspace. Just adding this for extra information.

local sound1 = 2696216972 

local sound2 = 1347686578 

local sound3 = 485221165 

local sound4 = 5911349360 

local sound5 = 4496252615 

local music = script.Parent

while true do

wait()

music.SoundId = "rbxassetid://2696216972" ..sound1

music:Play()

music.Ended: wait()

music.SoundId = "rbxassetid://5948571719" ..sound2

music:Play()

music.Ended: wait()

music.SoundId = "rbxassetid://2501021442" ..sound3

music:Play()

music.Ended: wait()

music.SoundId = "rbxassetid://501798669" ..sound4

music:Play()

music.Ended: wait()

music.SoundId = "rbxassetid://5911349360" ..sound5

music:Play()

music.Ended: wait()

end

What is music? And are you sure music is correctly indexed? The error means that you likely referred to music as workspace. Make sure your variables refer to their correct locations. Also where are you playing this from?

1 Like

the ids from the catalog. Though if you mean where is the script, its Workspace.MusicScript.

same as above.

Do i have to get them downloaded into inventory? or should i delete music.Parent?

If you’re playing it from the catalog, and I assume grabbing their Ids, they always a chance that they’ll fail to load. However, the issue seems to what you’re referring to (in this case ‘music’) is actually workspace. If your script is in workspace, and you’re referring to script.Parent, then music would be workspace itself?

1 Like

so Workspace.Script? or game.Workspace.MusicScript? Sorry, i’m terrible at coding. :cry:

local sound = yourSoundParent
sound.Parent = whereverYouWannaParent

local soundId = {
     "soundid";
     "soundid";
     "soundid";
     "soundid";
}

while true do
     for i = 1, #soundId do
          sound.SoundId = "rbxassetid"..soundId[i]
          sound:Play()
          sound.Ended:Wait()
     end
end

“Music” should refer to your sound object, not a script, due to properties such as SoundId.

So i should put these sounds into my game?

Try to make a list with all your sound and using for loop with repeat until like this script i just created

local sound = {2696216972, 1347686578,485221165, 4496252615}
local musicPlayer = script.Parent

while true do
  for i in pairs(sound) do
    musicPlayer.SoundId = "rbxassetid://"..sound[i]
    musicPlayer:Play()
    print("Playing ".. sound[i])
    repeat wait (1) until not musicPlayer.IsPlaying
    print("ended")
   end
end
2 Likes

12:26:30.884 - SoundId is not a valid member of Workspace "Workspace"

it just said this. highlighting this line of code.

musicPlayer.SoundId = "rbxassetid://"..sound[i]

was i supposed to change the “rbxassetid://”? If so, sorry, i’m an idiot.

but i don’t have any sound objects. Should i add them?

A sound object: sound
I was under the impression that ‘music’ was a sound object, and you were plugging in the sound ID’s into the sound objects soundID and playing it. Yes, I believe you would need a sound object to play the sound.

I didn’t want this to drag on forever, so I’ll clarify a few things. In order to play a sound, you need a sound object. You can set the SoundId via your code, without doing it manually.

local music = script.Sound -- Your sound object
music.SoundId = "rbxassetid://"..sound1-- Boom, you set the soundId and now you can play it
1 Like

Okay, my question is, how do i put all of the IDs into one sound object? Sorry if i seem dumb, just that i only saw one Sound ID spot. Should i just copy paste all of them into the sound ID?

Put the script in the Sound
character limitttttt

1 Like

Would you put the music in the game or no? Just the Id from the Libary?

just add the id in sound.
Ex : {MyId1, MyId2, MyId3}

Like here

1 Like

Fixed the code above a little so its checking for when the audio stops to start a new song.
Not sure if it is more optimized but it does not contain a repeat wait timer.
My apologies for bumping the thread but this was one of the first results on Google and I know more people are looking for a music player system.

local sound = {2696216972, 1347686578,485221165, 4496252615}
local musicPlayer = script.Parent.Sound

while true do
	for i in pairs(sound) do
		musicPlayer.SoundId = "rbxassetid://"..sound[i]
		musicPlayer:Play()
		print("Playing ".. sound[i])
		musicPlayer.Ended:Wait()
		print("ended")
	end
end