โ† Back to all scripts

Music Player

Plays a playlist of songs in order using SoundService. Loops automatically.

SystemsBeginnerServerScriptService
music-player.lua
-- Music Player
local SoundService = game:GetService("SoundService")
local PLAYLIST = {
    "rbxassetid://0000000001",
    "rbxassetid://0000000002",
}
local SHUFFLE = false
local currentIndex = 1
local bgm = Instance.new("Sound")
bgm.Volume = 0.5; bgm.Parent = SoundService

local function getNext()
    if SHUFFLE then return math.random(1, #PLAYLIST) end
    local n = currentIndex + 1; return n > #PLAYLIST and 1 or n
end

bgm.Ended:Connect(function() currentIndex = getNext(); bgm.SoundId = PLAYLIST[currentIndex]; bgm:Play() end)
if #PLAYLIST > 0 then bgm.SoundId = PLAYLIST[1]; bgm:Play() end
Related scripts in Systems
Basic Round SystemIntermediate โ†’Checkpoint SystemBeginner โ†’Day/Night CycleBeginner โ†’
Something broken or not working?
๐Ÿ”ง Try the AI Script Fixer โ†’