Need help with skipping sound for my music script

Is there’s a way to make a skip option for my music script? so every time you click a button it plays the next song.

here’s the script:

 local music = {"2529519176", "1333784441", "621227155"}
    local sound = script.Parent.Sound
    local muted = false

    while true do
    	for i = 1, #music do
    		sound.SoundId = "rbxassetid://"..music[i]
    		local Sound = script.Parent.Sound
            local id = Sound.SoundId:match("%d+")
            local Asset = game:GetService("MarketplaceService"):GetProductInfo(id)
    		script.Parent.SongName.Text = "Loading Song"
    		wait(3)
    		script.Parent.SongName.Text = "Now Playing: "..Asset.Name
    		sound:Play()
    		wait(sound.TimeLength)
end
end
2 Likes

Instead of waiting the length, try using the Playing feature of Sounds, so if a song is playing, it can be skipped/doesn’t play another song until it’s done playing. Use RemoteEvents to make Skipping a feature.

while true do
   if sound.Playing == false then
      local musictoPlay = music[math.random(1, #music)] --Random music
      --Play music
   end
end
2 Likes

How do i play the music then? 30 ch…

Here. I had just shortened it. (This worked upon testing it in a baseplate.)

while wait() do
   if sound.Playing == false then
      local musictoPlay = music[math.random(1, #music)] --Random music
      sound.SoundId = "rbxassetid://" .. musictoPlay
      local Sound = script.Parent.Sound
      local id = Sound.SoundId:match("%d+")
      local Asset = game:GetService("MarketplaceService"):GetProductInfo(id)
      script.Parent.SongName.Text = "Loading Song"
      wait(3)
      script.Parent.SongName.Text = "Now Playing: "..Asset.Name
      sound:Play()
   end
end

Edit : To make a Skip button, just change the sound.Playing to false if the Skip is successful.

1 Like

whenever i mute the music and unmute it does some weird stuff like skipping to a next sound or something.
heres the script for the unmute/mute button

local Button = script.Parent
local music = script.Parent.Parent.Sound
Button.MouseButton1Click:Connect(function()

if music.IsPlaying then
	music:Pause()
		Button.Text = 'Music: OFF'
        script.Parent.Parent.SongName.Visible = false
else
	Button.Text = 'Music: ON'
		music:Resume()
		script.Parent.Parent.SongName.Visible = true
end
end)

Instead of pausing it for the mute button, just make it turn the volume to 0.

is there any other way? 30 characters…

We’re flooding the thread, just move it to PMs if you have any more issues.
You can:
A. Turn the volume down to 0 if you mute the song
or
B. Make the script check if the music isn’t playing and if the music doesn’t have a paused boolean active

1 Like