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

how do i get the music to play at the right time?

so I wanted to publish this and make it so people didn't have to edit the script but it does not work there's not an error it just plays more than one song at a time how would i fix this?

-- SETTINGS
Numberofsoundz = 5 -- Put the number of Sounds you have inside of the script here

-- THE SCRIPT
math.randomseed(tick()) -- The random number generator! Guaranteed or your money back plus shipping and handling!
for _ = 1, math.huge do -- This basically tells the script to run forever.
	Soundisplaying = (math.random(Numberofsoundz)) -- The variable "Soundisplaying" equals the random number that was generated.
		if Soundisplaying == 1 then -- If the random number = 1, then do the following:
		script.S1:Play() -- Play S1, which is the name of the sound inside of the script.
		 wait(workspace.MusicScript.S1.TimeLength) -- The sound is 97.358 seconds long, so wait 98 seconds.
		elseif Soundisplaying == 2 then -- If the random number does not equal one, and it equals two, do the following:
		script.S2:Play()-- Play S2, which is the name of the sound inside of the script.
		wait (workspace.MusicScript.S2.TimeLength) -- You should understand this from the previous example.
		elseif Soundisplaying == 3 then -- I assume you understand what this does by now.
		script.S3:Play() -- You probally understand what this does.
		wait(workspace.MusicScript.S3.TimeLength)
		elseif Soundisplaying == 4 then
		script.S4:Play()
		wait(workspace.MusicScript.S4.TimeLength)
		elseif Soundisplaying == 5 then
		script.S5:Play()
		wait(workspace.MusicScript.S5.TimeLength)
		elseif Soundisplaying == 6 then
		script.S6:Play()
		wait(workspace.MusicScript.S6.TimeLength)
		elseif Soundisplaying == 7 then
		script.S7:Play()
		wait(workspace.MusicScript.S7.TimeLength)
		elseif Soundisplaying == 8 then
		script.S8:Play()
		wait(workspace.MusicScript.S8.TimeLength)
		elseif Soundisplaying == 9 then
		script.S9:Play()
		wait(workspace.MusicScript.S9.TimeLength)
		elseif Soundisplaying == 10 then
		script.S10:Play()
		wait(workspace.MusicScript.S10.TimeLength)
		end -- End of the if then statements.
end -- The end of the loop.
-- For more songs just add another elseif statement, another sound in the script, and change the Numberofsoundz.

1 answer

Instead of using

 wait(workspace.MusicScript.S1.TimeLength)

use

Workspace.Musicscript.[Sound here].Ended:Wait()

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