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

How do I make a script where the music playlist shuffles randomly?

Asked by 6 years ago

I've been on looking on YouTube for tutorials, but in the end I always get a bad result. Either the script doesn't work, or people make a script where the music is in a specific order. This is what I have right now, but I can't figure out what the problem is.

local Songs = {1062531124,1031544350,189078999,316561468,752710354,1326992990,272018606}

function PlayMusic()
    local Song = Instance.new("Sound",game.Workspace.Sounds)
    local ToPlay = Songs[math.random(1,#Songs)]
    Song.SoundId = "rbxassetid://"..tostring(ToPlay)
    Song:Play()
end

PlayMusic()

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local Songs = {1062531124,1031544350,189078999,316561468,752710354,1326992990,272018606}
local Autoplay = true  -- Didn't know if you wanted it to loop all songs


function PlayMusic()
    local Song = Instance.new("Sound",game.Workspace.Sounds)
    local ToPlay = Songs[math.random(1,#Songs)]
    Song.SoundId = "rbxassetid://"..ToPlay
    Song:Play()
    wait(.5)
    wait(Song.TimeLength)
    Song:Destroy()
    if Autoplay == true then
        PlayMusic()
    end
end

PlayMusic()
Ad

Answer this question