Music Script doesn't seem to work correctly

So I moved on from a previous script that was me literally manually writing a loop for each song I have (I have 70 in total btw, which adds up to about 400 lines of repeated code lol)

And I moved onto this code:

local SongBool = workspace.WorkspaceScripts:WaitForChild("MusicList")

for _,Song in ipairs(SongBool:GetChildren()) do
	if not Song:IsA("Sound") then continue end
end

-- Store the titles of each audio in a dictionary
local audioTitles = {
	Audio1 = "Caleb Belkin - Life";
	Audio2 = "Caleb Belkin - Water";
	Audio3 = "Lakey Inspired - Saydee";
	Audio4 = "peachy - falling for you (feat. mxmtoon)";
	Audio5 = "The Deli - 5:32PM";
	Audio6 = "atlas - defeated";
	Audio7 = "wunsche - sunday vibes";
	Audio8 = "(atlas, mt. fujitive) - discombobulated";
	Audio9 = "(atlas, mt. fujitive) - back then";
	Audio10 = "MrSirJohny_YT - s a y g o o d b y e";
	Audio11 = "Idealism - time will tell";
	Audio12 = "potsu - breakfast";
	Audio13 = "eevee - better";
	Audio14 = "GentleBeatz - Cold Night";
	Audio15 = "potsu - another.wun";
	Audio16 = "wun two - again";
	Audio17 = "Elijah Who - with all your love";
	Audio18 = "Engelwood - Crystal Dolphin";
	Audio19 = "HOME - Resonance";
	Audio20 = "Idealism - both of us";
	Audio21 = "atlas - internet personas";
	Audio22 = "Anna Yvette - Red Line";
	Audio23 = "eevvee - old places";
	Audio24 = "HM Surf - Trip to the Beach";
	Audio25 = "90sFlav - Call me";
	Audio26 = "H.1 - Return";
	Audio27 = "jinsang - feelings";
	Audio28 = "gnash - feelings faded";
	Audio29 = "love-sadKiD - My Oxygen";
	Audio30 = "eevvee - mist";
	Audio31 = "atlas - in between";
	Audio32 = "Jack Stauber - Buttercup";
	Audio33 = "Jack Stauber - Coffee";
	Audio34 = "atlas - chamomile";
	Audio35 = "Kudasai - serenade";
	Audio36 = "The Deli - 1:42AM";
	Audio37 = "The Deli - Tyner pt. 2";
	Audio38 = "Driver - The Eye of Truth";
	Audio39 = "The Deli - Moonlight.";
	Audio40 = "jinsang - affection.";
	Audio41 = "sugi.wa - ctrl.";
	Audio42 = "Tusken. X Philanthrope - Mr.Toast";
	Audio43 = "The Deli - Breeze";
	Audio44 = "Persona 5 Beneath the Mask";
	Audio45 = "Jack Stauber - Dead Weight";
	Audio46 = "WYS - Lone";
	Audio47 = "j'san - waking up in the park";
	Audio48 = "Gus Dapperton - Prune, You Talk Funny";
	Audio49 = "j'san - i’m in love with u, sorry";
	Audio50 = "SALES - renee";
	Audio51 = "Elijah Who - Cozy";
	Audio52 = "Elijah Who - Ends";
	Audio53 = "two sleepy - bloomed (slowed)";
	Audio54 = "potsu - oops";
	Audio55 = "potsu - lovesick";
	Audio56 = "Whitewoods - Beachwalk (Zen Remix)";
	Audio57 = "broey. - paradise";
	Audio58 = "Eddie Rohosy - Night ride";
	Audio59 = "Idealism - don’t say a word";	
	Audio60 = "Elijah Who - We used to talk every night";	
	Audio61 = "TRA$H - A L O N E";	
	Audio62 = "Kupla - fell in love in a dream";	
	Audio63 = "Elijah Who - A Cute Date";	
	Audio64 = "Elijah Who - hello";	
	Audio65 = "mt. fujitive - sundown";	
	Audio66 = "Idealism - nagashi";	
	Audio67 = "Jovial - Limes";	
	Audio68 = "Jack Stuaber - two time";	
	Audio69 = "Elijah Who - I'm in love";	
	Audio70 = "Saib - Sakura Trees";
}

-- Continuously go through all the songs, playing them
wait(10) -- Load time
while true do

	for _,Song in ipairs(SongBool:GetChildren()) do
		if not Song:IsA("Sound") then continue end
		game.workspace.JukeVibe.Sign.SurfaceGui.SongFrame.Song.Text = audioTitles[Song.Name]
		Song:Play()
		Song.Ended:Wait()  -- Properly waits for the song to end instead of using wait()

		wait(5) -- Time between songs
	end
end 

However, it seems to skip 7 songs, then play like normal, while only playing 1 song at the beginning when the server starts, then skipping the 7 perfectly fine sound objects in my SongBool folder.

boatbomber wrote this code for me, and I made some tweaks to remove the visualizer component because I had to do that local.

Any help would be greatly appreciated.

Are they missing from the songbool folder?
Are they missing from songbool:GetChildren()?
Is the continue section of the loop running when they skip over?
Are the songs properly ordered in workspace?
Do they ever play, just misordered, or do they never play at all like they dont exist?

No, I’ve checked that all 70 are there.

GetChildren creates a table of children, so since the 70 exist, it should be fine.

Since it runs after each song is played, I assume so.

It goes by Audio1, Audio2, Audio3, etc.

Some play, and some don’t at all, even though they’re all there, but they do play in order yes. Some just don’t play.

The continue portion should only run when an invalid object is iterated over, if its running every single song that might be a problem

I’m pretty sure that only runs if finds something is not a sound object, so that line shouldn’t be affected. Sorry I think I misunderstood for a moment.

Have you tried adding a print statement into the continue thing to see if or when it runs?

I haven’t done that yet, I’ll try doing that right now, and will troubleshoot further :ok_hand:

I have to get some sleep right now, but I will contact you again tomorrow when I’m available. Goodnight.

@PapaBreadd Okay, I added the print statement inside the continue part of the script that plays the songs.

It just says the normal “I loaded the song!” even though it would have spammed if it quickly skipped over the songs.

The audio 1 title of this screenshot:
image
goes to the 10th song in the playlist. For some reason, it skips everything 2-9.

I’m really stumped, as they are all sound objects, and it does play the first song, and all the rest after 10 perfectly fine.

I believe this may be another instance on Sounds attempting to play in-between loops? Sometimes, there’s the weird chance of Sounds not being able to play certain ID’s when they’re encased inside a loop

Maybe try this?

-- Continuously go through all the songs, playing them
wait(10) -- Load time
while true do

	for _,Song in ipairs(SongBool:GetChildren()) do
		if not Song:IsA("Sound") then continue end
		game.workspace.JukeVibe.Sign.SurfaceGui.SongFrame.Song.Text = audioTitles[Song.Name]
        if not Song.IsLoaded then
            Song.Loaded:Wait()
        end

		Song:Play()
		Song.Ended:Wait()  -- Properly waits for the song to end instead of using wait()

		wait(5) -- Time between songs
	end
end 

If this script still keeps skipping songs, then that’s more than likely the reason why

1 Like

Yeah unfortunately this is true, and the script still skips the Audio2 - Audio9 songs. This is confusing, I just can’t see what’s wrong here. I appreciate the help

The fortunate thing about this though, is that there is a workaround

Although you’d need to resort to Cloning the Sounds & instead, but looking back at it again I believe it can be possible

Can you try this?

-- Continuously go through all the songs, playing them
wait(10) -- Load time
while true do

	for _,Song in ipairs(SongBool:GetChildren()) do
		if not Song:IsA("Sound") then continue end
		game.workspace.JukeVibe.Sign.SurfaceGui.SongFrame.Song.Text = audioTitles[Song.Name]
        local CloneSong = Song:Clone()
        CloneSong.Parent = SongBool
		CloneSong:Play()

		CloneSong.Ended:Wait()  -- Properly waits for the song to end instead of using wait()

        CloneSong:Destroy()
		wait(5) -- Time between songs
	end
end

Are these 2 supposed to be different? And I would have to move the songs out of SongBool, and into a server backup folder and get the children there, which is fine. I’ll try it.

It’s just setting the Parent of the Sound to where it’s supposed to play, for some reason if you don’t set it, it won’t work

I know, I simply meant the spelling. “CloseSong” is no where to be found in the script. Only “CloneSong”

Oh that was a mistake on my end WHOOPS-

Yeah just change the name of mistypo and you should be all set hopefully?

1 Like

It seems as if we are now further than we started. It now skips songs Audio1 - Audio9.

O k a y

Are you sure that all of the Audio Songs that you entered are valid? Or maybe you messed something up within your Explorer?

No, I can confirm that they are all there, and all the IDs are in there. I can literally play Audio1-9 manually. Why would Audio1 fail if it was playing before? X_X

Thank you for the effort.

I just noticed something that I believe is crucial. Turns out the regular code was working just fine, it was just going in order of what was shown in the explorer. Sadly, it’s not sorted by Number.

image

I just don’t know how to get it to recognize the proper order.