Hello everyone, I’m currently having an issue with a Music playlist Script.
It is breaking randomly after 5min - 10h when a Song ends. I’m unsure if it breaks when it’s unable to load a Song, or what the issue actually is.
while true do
for _,song in pairs(Playlist) do
wait()
print("ID: ".. song)
script.Parent:WaitForChild("Sound").SoundId = "rbxassetid://".. song
script.Parent:WaitForChild("Sound")
script.Parent:WaitForChild("Sound").TimePosition = 0
repeat wait() until script.Parent:WaitForChild("Sound").IsLoaded == true
script.Parent:WaitForChild("Sound"):Play()
repeat wait() until script.Parent:WaitForChild("Sound").IsPlaying == true
local Asset = game:GetService("MarketplaceService"):GetProductInfo(song)
warn("Playing: "..Asset.Name)
script.Parent.songname.Value = Asset.Name
repeat wait() until script.Parent:WaitForChild("Sound").IsPlaying == false or script.Parent:WaitForChild("Sound").TimePosition == script.Parent:WaitForChild("Sound").TimeLength
wait(0.5)
workspace.MusicSystem.Sound:Stop()
wait()
end
wait()
end
If you have any other way to make the Playlist more efficiant, feel free to tell me
You could try using the pcall() function or preloading the soun. Or you could keep the sounds in a folder and use :Play() on them so the script itself never deals with loading the sound IDs.
I think having the sounds in the folder and using the Play() function on them would be easiest. I also just tested the sound ID which was in the error message in the screenshot. It wouldn’t load for me either so you probably need to remove it
I would recommend putting that in a codeblock by embedding it in 3 backticks. Also, no need for the for loop. Just store SoundFolder:GetChildren() as a variable then do SoundFolder[ChosenSong]. As well, no need to put a wait(n) in there. The Sound instance has a built-in .Ended event so you can do Sound.Ended:Wait().