Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i fix the multiple music script (multiple songs playing at once)?

So basically, I've been making a game and I've added a script which adds multiple songs instead of one. So, when I test out the game, the music starts but they ALL start at once. Sound1 is located in the workspace, sound2 is inside sound1, sound 3 inside sound2 so on so forth, anyways, here's the script:


local sound1 = 2529519176
local sound2 = 500155118
local sound3 = 1930853637
local sound4 = 1468374269
local music = script.Parent
    while true do
wait()
music.SoundId= "rbxassetid://"..sound1
music:Play()
music.Ended: wait()


music.SoundId= "rbxassetid://"..sound2
music:Play()
music.Ended: wait()


music.SoundId= "rbxassetid://"..sound3
music:Play()
music.Ended: wait()


music.SoundId= "rbxassetid://"..sound4
music:Play()
music.Ended: wait()
    

   end



2 comments

0

Wait for the song to load using the event Loaded. You can use the wait method on the Loaded event for waiting until the song loads (Loaded fires when a SoundId loads).

0

^ Answered right there.

2 answers

✓ Accepted answer

well; you could try this:

local music = script.Parent
local current_index = 1
local songs = {
	2529519176;
	500155118;
	1930853637;
	1468374269;
}

music.SoundId = "rbxassetid://"..songs[current_index];
music:Play()

music.Ended:Connect(function()
	if songs[current_index+1] then
		current_index = current_index+1;
	else
		current_index = 1;
	end

	music.SoundId = "rbxassetid://"..songs[current_index];
	music:Play()
end)

it just listens for when one song ends and plays the next one in the array (if there is one present) otherwise , it just returns at the first one in the array

this will allow you to end more songs without having to write any code

hello, im in a bad mood, so this will not be a really god answer, but you could just find how long each song is, then write (for example- if song a is 500 long and b is 30 long)then)

while true do
a:Play()
wait(500)
b:Play()
wait(30)
end

but if you really wanted ur way, then i think the problem is no parenthesis. it probably should be

music.SoundId= ("rbxassetid://"..sound1)
music:Play()

instead of

music.SoundId= "rbxassetid://"..sound1
music:Play()

4 comments

0

and i have no idea of music:ended : wait() is a real thing, but if you really can put : wait then thats not a problem

0

It is a thing. wait is a function of every event which yields the thread until that event is fired at least once. The problem was that the song did not load before listening to Ended, so I'm guessing Play fired Ended right away.

0

good catch pidgey

0

The problem with finding the length of each sound/song is that it's redundant and difficult to handle after a while. The purpose of scripting is to make your life easier and you'd want to utilize the tactics you can.

This discussion is preserved as it was. New answers, comments, and votes are closed.