Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Omzure 94
5 years ago

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
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). pidgey 548 — 5y
0
^ Answered right there. kittonlover101 201 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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()
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 idunnobut 27 — 5y
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. pidgey 548 — 5y
0
good catch pidgey CommanderCaubunsia 126 — 5y
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. M39a9am3R 3210 — 5y

Answer this question