Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.