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 8 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?

ID = '317251079' -- Music ID
Looped = true -- False for Non-Looping Music

Music=Instance.new("Sound" ,Workspace)
Music.Name = "Music"
if Looped == true then
Music.Looped = true
end
Music.SoundId = "http://roblox.com/asset/?id=317251079" -- Music ID
Music:Play()

2 answers

Log in to vote
1
Answered by 8 years ago
local musicTracks = {
    "http://roblox.com/asset/?id=317251079",
    "add more"
}

music = musicTracks[math.random(1,#musicTracks)]
music:Play()

0
Thx! I'll try to test it out. I see how it works now. DerpyShadowz 34 — 8y
0
Yeah, it works now, when I add this in. Thx again. DerpyShadowz 34 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local musicPlaylists = {
"http://roblox.com/asset/?id=317251079",
" add more"
}
Music.Ended:(connect(function()

Music.SoundId = musicPlaylists[math.random(1,#musicPlaylists)]
Music:Play()
end)

Answer this question