Help with music script

Hi i am trying to make a music system yet my script does not work, could i please have some help.

local muteButton = script.Parent.Mute
local skipButton = script.Parent.Skip
local currentSongDisplay = script.Parent.CurrentSongDisplay
local musicPlayer = script.Parent.Music

local marketplaceService = game:GetService("MarketplaceService")

local songs = {
	1837692031, --Some song that I made a while back
	1837324500, --That "Putin Walk" meme
	1839448308, --Revenge - Jailbreak Parody
	1836965691,
	1838569831,
	1840402188,
	1838569831,
	1843382633,
	1842940253,
	1838742547,
	1842522056
	--PewDiePie - Floor Gang
}

muteButton.Activated:Connect(function()
	if musicPlayer.IsPaused == false then
		musicPlayer:Pause()
		
	else
		musicPlayer:Resume()
		
	end
end)

skipButton.Activated:Connect(function()
	musicPlayer.TimePosition = musicPlayer.TimeLength
end)

while true do
	for count = 1, #songs do
		musicPlayer.SoundId = "rbxassetid://"..songs[count]
		songInfo = marketplaceService:GetProductInfo(songs[count])
		musicPlayer.Loaded:Wait()
		musicPlayer.TimePosition = 0
		musicPlayer:Play()
		currentSongDisplay.Text = "Now playing: "..songInfo.Name
		musicPlayer.Ended:Wait()
		currentSongDisplay.Text = "Loading next song..."
	end
end

image
thanks for youth help

I don’t usually use for i = min, max do end loops when it comes to sounds what I usually do is

take this code for example

local thisTbl = {
   whateverthisnameisfor = ...; -- song id
   this2 = ...;
}

-- loop it in a while
while true do
   -- loop it in a while to get the name of each children and its id
   for SongName, SongId in pairs(thisTbl) do
       -- Sound Creation
       local newSound = Instance.new("Sound")
       newSound.Parent = ...
       newSound.SoundId = thisTbl[SongName]
       
       --check if it exists if not then error it since it maybe critical for our game
       assert(newSound, "sound does not exist")
       
       -- playing and waiting for it to end then play another one
       newSound:Play()
       newSound.Ended:Wait()
   end
end
1 Like