Basically, This code works. I am little bit confused on how it works, can someone add comments beside every line (expect the ones where I have defined the Music)
01 | local MusicOne = game.SoundService.MusicOne |
02 | local MusicTwo = game.SoundService.MusicTwo |
03 | local MusicThree = game.SoundService.MusicThree |
04 | local MusicFour = game.SoundService.MusicFour |
05 | local MusicFive = game.SoundService.MusicFive |
06 | local function play(sound) |
07 | sound:Play() |
08 | sound.Ended:Wait() |
09 | end |
10 | while true do |
11 | play(MusicOne) |
12 | play(MusicTwo) |
13 | play(MusicThree) |
14 | play(MusicFour) |
15 | play(MusicFive) |
16 | end |
Simply imagine anything that you put in the place of the parameter sound, ends up replacing it in the code.
01 | local MusicOne = game.SoundService.MusicOne |
02 | local MusicTwo = game.SoundService.MusicTwo |
03 | local MusicThree = game.SoundService.MusicThree |
04 | local MusicFour = game.SoundService.MusicFour |
05 | local MusicFive = game.SoundService.MusicFive |
06 |
07 |
08 | local function play(sound) -- Here you have defined a function called play, and defined the parameter 'sound' that you will input later |
09 |
10 | sound:Play() -- When you enter the name of a sound (e.g. MusicOne), it replaces the parameter, so it's the same as doing MusicOne:Play() |
11 |
12 | sound.Ended:Wait() -- Once the song has ended, the function waits |
13 |
14 | end |
15 |
01 | --These five lines define sounds already set up in the sound service (I think) |
02 | local MusicOne = game.SoundService.MusicOne |
03 | local MusicTwo = game.SoundService.MusicTwo |
04 | local MusicThree = game.SoundService.MusicThree |
05 | local MusicFour = game.SoundService.MusicFour |
06 | local MusicFive = game.SoundService.MusicFive |
07 |
08 | --This function takes in one parameter, the sound (one of the ones above) |
09 | local function play(sound) |
10 | sound:Play() --This plays the sound |
11 | sound.Ended:Wait() --This waits until the sound finishes |
12 | end |
13 |
14 | --Loops infinitely |
15 | while true do |
This is a basic overview of what happens with this script. If you would like more explanation on the sound.Ended:Wait()
part I have a video on my YouTube Channel all about events right here