I am using the tutorial from https://developer.roblox.com/en-us/articles/sounds-and-music

and it works for a single song but how do i modify it to add multiple songs to be played sequentially?

local AudioPlayer = {}
 
-- Roblox services
local ContentProvider = game:GetService("ContentProvider")
 
-- Function to preload audio assets
AudioPlayer.preloadAudio = function(assetArray)
	local audioAssets = {}
 
	-- Add new "Sound" assets to "audioAssets" array
	for name, audioID in pairs(assetArray) do
		local audioInstance = Instance.new("Sound")
		audioInstance.SoundId = "rbxassetid://" .. audioID
		audioInstance.Name = name
		audioInstance.Parent = game.Workspace
		table.insert(audioAssets, audioInstance)
	end
 
	local success, assets = pcall(function()
		ContentProvider:PreloadAsync(audioAssets)
	end)
end
 
-- Function to play an audio asset
AudioPlayer.playAudio = function(assetName)
	local audio = game.Workspace:FindFirstChild(assetName)
	if not audio then
		warn("Could not find audio asset: " .. assetName)
		return
	end
	if not audio.IsLoaded then
		audio.Loaded:wait()
	end
	audio:Play()
end
 
return AudioPlayer


--new local script 

-- Roblox services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
-- Require module
local AudioPlayerModule = require(ReplicatedStorage:WaitForChild("AudioPlayer"))
 
-- Preload music tracks
AudioPlayerModule.preloadAudio({
	["Lucid_Dream"] = 1837103530,
	["Desert_Sands"] = 1848350335
})
 
-- Play music track
AudioPlayerModule.playAudio("Lucid_Dream")

1 comment

0

you can wait for the Ended event to occur, then when it has occurred, play the next song