Song in playlist not transition to next song

Hi there, I have a music playlist that loops through all the id’s provided in the script randonly, and plays it individually on one sound object. The issue is, is that the loop doesn’t play the next song. I have a value in the loop that tells the current song playing, so that seemed to change but not the song. In studio, the song resets at time position 0 and stops.

local MPS = game:GetService("MarketplaceService")
local currentTrack = game.ReplicatedStorage.CurrentTrack 
local CurrentCamera = workspace.CurrentCamera
local musicplayer = workspace.Sound

music = {
	"rbxassetid://3044286747",
	"rbxassetid://1256391355",
	"rbxassetid://5480102561",
	"rbxassetid://5024527209",
	"rbxassetid://870242868",
	"rbxassetid://1112109949",
	"rbxassetid://6303331764",
	"rbxassetid://2206587324",
	"rbxassetid://5987864893",
	"rbxassetid://534429024",
	"rbxassetid://4551177864",
	"rbxassetid://664277618",
	"rbxassetid://3011342543",
	"rbxassetid://3523361267",
	"rbxassetid://3616424949";

}

while true do 

	local RandomSong = music[math.random(1, #music)]
	local SongID = string.match(RandomSong, "%d+")
	local SongInfo = MPS:GetProductInfo(SongID)

	musicplayer.SoundId = RandomSong
	musicplayer:Play()

	currentTrack.Value = "..." -- displays the song playing in a music player gui

	currentTrack.Value = SongInfo.Name -- just for displaying current song playing

	musicplayer.Ended:Wait()

	game:GetService("RunService"):UnbindFromRenderStep("CurrentTrack")

end

local MPS = game:GetService("MarketplaceService")
local currentTrack = game.ReplicatedStorage.CurrentTrack 
local CurrentCamera = workspace.CurrentCamera
local musicplayer = workspace.Sound

music = {
	"rbxassetid://3044286747",
	"rbxassetid://1256391355",
	"rbxassetid://5480102561",
	"rbxassetid://5024527209",
	"rbxassetid://870242868",
	"rbxassetid://1112109949",
	"rbxassetid://6303331764",
	"rbxassetid://2206587324",
	"rbxassetid://5987864893",
	"rbxassetid://534429024",
	"rbxassetid://4551177864",
	"rbxassetid://664277618",
	"rbxassetid://3011342543",
	"rbxassetid://3523361267",
	"rbxassetid://3616424949"
}

while true do
	local RandomSong = music[math.random(1, #music)]
	local SongID = string.match(RandomSong, "%d+")
	local SongInfo = MPS:GetProductInfo(SongID)
	musicplayer.SoundId = RandomSong
	musicplayer:Play()
	currentTrack.Value = "..." -- displays the song playing in a music player gui
	currentTrack.Value = SongInfo.Name -- just for displaying current song playing
	musicplayer.Ended:Wait()
end

You don’t need UnbindFromRenderStep because BindToRenderStep is never called from within the script.

1 Like

Now the song transitions, but it doesn’t transition to the start of the song and rather the middle or last.

For some reasons, this bug performs differently in studio testing than in game

On studio testing it works, but not in game.

local MPS = game:GetService(“MarketplaceService”)
local currentTrack = game.ReplicatedStorage.CurrentTrack
local CurrentCamera = workspace.CurrentCamera
local musicplayer = workspace.Sound

music = {
“rbxassetid://3044286747”,
“rbxassetid://1256391355”,
“rbxassetid://5480102561”,
“rbxassetid://5024527209”,
“rbxassetid://870242868”,
“rbxassetid://1112109949”,
“rbxassetid://6303331764”,
“rbxassetid://2206587324”,
“rbxassetid://5987864893”,
“rbxassetid://534429024”,
“rbxassetid://4551177864”,
“rbxassetid://664277618”,
“rbxassetid://3011342543”,
“rbxassetid://3523361267”,
“rbxassetid://3616424949”;

}
while true do
if not musicplayer.IsPlaying then
local RandomSong = music[math.random(1, #music)]
local SongID = string.match(RandomSong, “%d+”)
local SongInfo = MPS:GetProductInfo(SongID)

       musicplayer.SoundId = RandomSong
       musicplayer:Play()

       currentTrack.Value = "..." -- displays the song playing in a music player gui

       currentTrack.Value = SongInfo.Name -- just for displaying current song playing

        musicplayer.Ended:Wait()

        game:GetService("RunService"):UnbindFromRenderStep("CurrentTrack")
    end

end

That seemed to work, thanks!

you’re welcome I’m glad to help you :thinking:

local MPS = game:GetService("MarketplaceService")
local currentTrack = game.ReplicatedStorage.CurrentTrack 
local CurrentCamera = workspace.CurrentCamera
local musicplayer = workspace.Sound

music = {
	"rbxassetid://3044286747",
	"rbxassetid://1256391355",
	"rbxassetid://5480102561",
	"rbxassetid://5024527209",
	"rbxassetid://870242868",
	"rbxassetid://1112109949",
	"rbxassetid://6303331764",
	"rbxassetid://2206587324",
	"rbxassetid://5987864893",
	"rbxassetid://534429024",
	"rbxassetid://4551177864",
	"rbxassetid://664277618",
	"rbxassetid://3011342543",
	"rbxassetid://3523361267",
	"rbxassetid://3616424949"
}

while not musicplayer.IsPlaying do
	local RandomSong = music[math.random(1, #music)]
	local SongID = string.match(RandomSong, "%d+")
	local SongInfo = MPS:GetProductInfo(SongID)
	musicplayer.TimePosition = 0
	musicplayer.SoundId = RandomSong
	repeat
		task.wait()
	until musicplayer.IsLoaded
	musicplayer:Play()
	currentTrack.Value = "..." -- displays the song playing in a music player gui
	currentTrack.Value = SongInfo.Name -- just for displaying current song playing
	musicplayer.Ended:Wait()
end

Because you’re using a single Sound instance you should be using “IsLoaded” to determine when the sound instance has loaded before playing it.

game:GetService("RunService"):UnbindFromRenderStep("CurrentTrack")

This line is redundant.

1 Like

I see. I’m having issues with in-game roblox so I’m going to write a topic down.