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

How to make a script which plays a random song after one has finished?

Asked by 9 years ago

So basically, I'm trying to get a script to play a song, when the game starts, then once that has finished, I want it to play a different song, picked randomly from a list. So how would I do that? I've gotten the basics of the loops, but only of one song. Can someone help please?

01ID = '317251079' -- Music ID
02Looped = true -- False for Non-Looping Music
03 
04Music=Instance.new("Sound" ,Workspace)
05Music.Name = "Music"
06if Looped == true then
07Music.Looped = true
08end
09Music.SoundId = "http://roblox.com/asset/?id=317251079" -- Music ID
10Music:Play()

2 answers

Log in to vote
1
Answered by 9 years ago
1local musicTracks = {
3    "add more"
4}
5 
6music = musicTracks[math.random(1,#musicTracks)]
7music:Play()
0
Thx! I'll try to test it out. I see how it works now. DerpyShadowz 34 — 9y
0
Yeah, it works now, when I add this in. Thx again. DerpyShadowz 34 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
1local musicPlaylists = {
3" add more"
4}
5Music.Ended:(connect(function()
6 
7Music.SoundId = musicPlaylists[math.random(1,#musicPlaylists)]
8Music:Play()
9end)

Answer this question