Script only plays one song. Need it to play multiple. (Script attached)

Hey, let’s start of by saying I am not a scripter, this is the first script that I ever made myself so it may be badly optimised etc.
I am trying to make it so my script picks a random song, plays said song, picks another random song, plays said song etc, etc.
For some reason my script only plays one song, that’s my issue.
What I would like for someone to do is to either tell me what to put and where or copy my script and add what is needed to be added.
Sadly there is no pay as I have literally nothing to offer.
Here is my script:


local sound1 = 717543378
local sound2 = 1893107102	
local sound3 = 573369104
local sound4 = 4620422621
local sound5 = 587498104
	
	
local music = script.Parent


function Song()
	local song = math.random(1,5)
	if song == 1 then
		music.SoundId = "rbxassetid://"..sound1
	else if song == 2 then
			music.SoundId = "rbxassetid://"..sound2
		else if song == 3 then
				music.SoundId = "rbxassetid://"..sound3
				else if song == 4 then
						music.SoundId = "rbxasset:"..sound4
					else if song == 5 then
							music.SoundID = "rbxasset:"..sound5
						end
			end
		end
	end
	end
	end

	
while true do 
	wait()
	Song()
	wait(.1)
	music:Play()```

Thanks a bunch guys!

FYI, “Thanks a bunch guys”! isn’t inside of my script.

WHy don’t you just try using math.random?
Edit:
why dont’ you just use math.random and have a table full of songs in there?

Not really sure what you mean. So sorry if it’s really obvious.

I’m saying why dont you put music IDs inside a table then use math.random to play it

I would say can you please type the script for me but since this is literally free work I am not going to ask.

I am going to take your answer and say thanks. I’ll have a look into it.

You should just store the songs in a table and loop through them, for the random song this is what I did:

local RandomSong = Songs[math.random(1, #Songs)]
RandomSong:Play()
RandomSong.Ended:Wait()

Would that be the entire script?

No it wouldn’t, but since I already made a script I will just give you the code:

local GenreFolder = game.Workspace:WaitForChild("Genre")--Store your songs as Sounds in a folder

local Folder = GenreFolder:WaitForChild("NewWave")
local Songs = Folder:GetChildren()

local RandomSong = Songs[math.random(1, #Songs)]
RandomSong:Play()
RandomSong.Ended:Wait()


while true do
	for i, song in pairs(Songs) do
		if song:IsA("Sound") then
			song:Play()
			song.Ended:Wait()
		end
	end
end

I do highly appreciate that! Thanks a bunch! :slight_smile:

1 Like

Also why is this topic on building support it should be on #help-and-feedback:scripting-support

So sorry, I just updated that now. Thanks for letting me know!
This was my first ever post here.
I just updated it.

1 Like