Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
1
Answered by
Invisum -5
9 years ago

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


0
music plays for like 0.5 secs then stops o.o Layfonex 0 — 9y
0
worked in test but wouldnt switch to next song Layfonex 0 — 9y
0
now it works, I made a mistake. Sorry about that, it's because I woke up a few minutes ago, lol Invisum -5 — 9y
0
Wait, again, doesn't work! Don't worry, I will fix it. Sorry about that Invisum -5 — 9y
View all comments (18 more)
0
+1, for good Explanation! woodengop 1134 — 9y
0
Ok, I am testing it... Almost done! :) Invisum -5 — 9y
0
thanks ~ ! Layfonex 0 — 9y
0
Ok, so, ROBLOX's IsPlaying value for audios isn't working properly.. So I used the TimeLenght value to make the script wait Invisum -5 — 9y
0
um.. its playing all the songs at once XD Layfonex 0 — 9y
0
Oh.. I am sorry, I will fix it Invisum -5 — 9y
0
I think I found what I did wrong.. Lol Invisum -5 — 9y
0
oh ok :3 Layfonex 0 — 9y
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 Invisum -5 — 9y
0
is it working now ? Layfonex 0 — 9y
0
sorry for making you wait so much.. I had to debug it Invisum -5 — 9y
0
Ok, I think I debugged it, it works on studio, so, I will test it on a game Invisum -5 — 9y
0
This is strange.. It works well on ROBLOX studio but it doesn't work properly in games.. :( I will try.. Invisum -5 — 9y
0
like replay every few seconds then play all at once Layfonex 0 — 9y
0
Yeah! I don't know why that happens, the scrpt works properly at roblox studio. I am trying to fix it.. Invisum -5 — 9y
0
I gtg now, sorry :( Cya! I will try to fix it later. Invisum -5 — 9y
0
oh ok Layfonex 0 — 9y
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. Invisum -5 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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

Answer this question