Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why does all the music play at once instead of 1 by 1 ?

all music playing at the same time.... i want it to play then play next random song once the other finishes

while true do
wait(0)	
script:FindFirstChild("Music"..math.random(1,4)):Play()
end

2 answers

✓ Accepted answer

Firstly, lets rename the script with a new name (e.g. MUSICPLAYER) So, lets say you have 4 different audios which are all located in game.Workspace.MUSICPLAYER

Here is what you need to write to make it work: (it is tested, it works and it is random(whereas math.random is not very random))

Note: I am still working on it.....

 wait(10) --waiting for the assets to load properly
music = script:GetChildren()
a = true
while a == true do
wait(1)
a = false
for i,v in pairs(music) do
math.randomseed(tick()*math.random())
local MusicRandom = music[math.random(1,#music)]
MusicRandom:Play()
wait(4)
repeat wait() until MusicRandom.TimePosition == 0
if MusicRandom.TimePosition == 0 then
wait(1.5)
a = true
end
end
end


22 comments

0

music plays for like 0.5 secs then stops o.o

0

worked in test but wouldnt switch to next song

0

now it works, I made a mistake. Sorry about that, it's because I woke up a few minutes ago, lol

0

Wait, again, doesn't work! Don't worry, I will fix it. Sorry about that

0

+1, for good Explanation!

0

Ok, I am testing it... Almost done! :)

0

thanks ~ !

0

Ok, so, ROBLOX's IsPlaying value for audios isn't working properly.. So I used the TimeLenght value to make the script wait

0

um.. its playing all the songs at once XD

0

Oh.. I am sorry, I will fix it

0

I think I found what I did wrong.. Lol

0

oh ok :3

0

Ok, so, I made a few changes and now it works in ROBLOX studio, now I will test it in an actual game to see if it works

0

is it working now ?

0

sorry for making you wait so much.. I had to debug it

0

Ok, I think I debugged it, it works on studio, so, I will test it on a game

0

This is strange.. It works well on ROBLOX studio but it doesn't work properly in games.. :( I will try..

0

like replay every few seconds then play all at once

0

Yeah! I don't know why that happens, the scrpt works properly at roblox studio. I am trying to fix it..

0

I gtg now, sorry :( Cya! I will try to fix it later.

0

oh ok

0

I am back. I am sorry but, I have to work on my project, do homework etc.. I can't debug this, but, I tried.

You are not checking if the song has finished before playing the next sound. Click here for sound api

You need to check the sound using this Click here

This script just shows you how it works, it is untested as I don't have the time atm.

local soundName = ""
while true do
wait(0.5) 
	if not script.soundName.IsPlaying then
		soundName ="Music"..math.random(1,4)
		local sound = script:FindFirstChild(soundName)
		sound:Play()
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.