Music System Script doesn't work

Hey! I am currently a new scripter and I have watched quite a few tutorials on how to create my own Music System. I kept it so something basic, as I did not want a Mute button or a Skipping System. Due to a few Youtube tutorials not helping at all, I decided to use the Devforum for some help and support.

It has came to my attention that when I tried testing the game, the first song played perfectly, then the next few ones did not at all. I changed the script a couple of times, but nothing worked, so I decided to delete a few songs from the actual playlist and came to the conclusion that I have only 4 left.

How do I make it so every single song plays instantly after the previous one has successfully ended?

game.Workspace.Calming:Play()
wait(48)
game.Workspace.Temporex:Play()
wait(181)
game.Workspace.Chetta:Play()
wait(29)
game.Workspace.Lovely:Play()
wait(64)

image

I believe you need the music to be the child of the script. Or have some way to tell it where the music is.

Example:

Game.workspace.audio

Edit:

This should help for more tutorials look on the DevForum or YouTube.

1 Like

You can use the Ended event to detect when a song ends, but if you use :Wait() on the event, it’ll wait until the event has been fired:

game.Workspace.Calming:Play()
game.Workspace.Calming.Ended:Wait()
game.Workspace.Temporex:Play()
game.Workspace.Temporex.Ended:Wait()
game.Workspace.Chetta:Play()
game.Workspace.Chetta.Ended:Wait()
game.Workspace.Lovely:Play()
game.Workspace.Lovely.Ended:Wait()

However, after the last song, it’ll just stop. If you want it to repeat, put it in a while loop

5 Likes

Do they need to loop? I’d use the following script:

while true do
  script.Parent.Calming:Play()
  script.Parent.Calming.Ended:Wait()
  script.Parent.Temporex:Play()
  script.Parent.Temporex.Ended:Wait()
  script.Parent.Chetta:Play()
  script.Parent.Chetta.Ended:Wait()
  script.Parent.Lovely:Play()
  script.Parent.Lovely.Ended:Wait()
end

the sounds and script are both parented to the same object, it should work if it’s in a service where server scripts are able to run

2 Likes

Would be even better to just use a single audio object and have the script update the asset Id instead of playing each individual audio one after the other.

2 Likes

Yeah, its way better to use the Ended event instead of adding a wait on how long the music is going to last for.

1 Like

Instead of using wait, I’d recommend waiting until the Ended event of the Sound object is fired, and then connecting with a a Wait().

But wait. What happens after the last song is played? It’ll stop.
This is why we need to put it in a loop. So that it can repeat indefinitely.

while true do
    game.Workspace.Calming:Play()
    game.Workspace.Calming.Ended:Wait()
    game.Workspace.Temporex:Play()
    game.Workspace.Temporex.Ended:Wait()
    game.Workspace.Chetta:Play()
    game.Workspace.Chetta.Ended:Wait()
    game.Workspace.Lovely:Play()
    game.Workspace.Lovely.Ended:Wait()
end
1 Like