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

How do you make this script loop?

Asked by
Irvene 5
9 years ago

I've been trying to make a looping music script, and this is what I've gotten so far in progress;

ID = '142463279' -- Set the ID to the music you want to play.
Looped = false -- Set to false if you want non-looped music.

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

wait(120)
Game.Workspace.Music:remove()

ID = '142650764' -- Set the ID to the music you want to play.
Looped = false -- Set to false if you want non-looped music.

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

wait(120)
Game.Workspace.Music:remove()

ID = '133217882' -- Set the ID to the music you want to play.
Looped = false -- Set to false if you want non-looped music.

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

wait(120)
Game.Workspace.Music:remove()

ID = '170691997' -- Set the ID to the music you want to play.
Looped = false -- Set to false if you want non-looped music.

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

1 answer

Log in to vote
1
Answered by
Relatch 550 Moderation Voter
9 years ago

Instead of doing this 3 times, just use a while true do loop. This loop is infinite. When using a while true do loop, always remember to wait before ending it. Otherwise, studio will crash.

ID = "142463279"
Looped = false

while true do
    Music = Instance.new("Sound", workspace)
    Music.Name = "Music"
    if Looped == true then
        Music.Looped = true
        Music.SoundId = "http://roblox.com/asset/?id=142463279" 
        Music:Play()
    end
    wait(120)
    game.Workspace.Music:Destroy()
end
Ad

Answer this question