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

Why does my music script keep repeating music when people join?

Hi, when people join my place, the music keeps playing from my script.

Here is the script:

while true do

game.Workspace.song1name:Play()

wait(song1length)

game.Workspace.song2name:Play()

wait(song2length)

end

It is a LOCAL Script, and I've tried putting it in many places such as Workspace and StarterGUI, but everytime it keeps repeating. I've tried a normal script too.

1 answer

You need to see if the sound is started, otherwise it spams the sound, try something like this:

function startSong()
	local isStarted1 = false
	local isStarted2 = false
	while true do
		if not isStarted1 then
			game.Workspace.song1name:Play()
			isStarted1 = true
			wait(song1length)
			game.Workspace.song1name:Stop()
			isStarted1 = false
		elseif not isStarted 2 then
			game.Workspace.song1name:play()
			isStarted2 = true
			wait(song2length)
			game.Workspace.song2name:Stop()
			isStarted2 = false
		end
		wait(1) -- Wait 1 second before relooping again, or it will crash for StackOverflow (infinite loop)
	end
end
startSong()

9 comments

0

Thanks so much.

1

You can now upvote, that was a good question =)

1

Thanks :D

0

Does it have to be in a specific place?

0

StarterGui

0

Ok, if I add more music, do I just add another isStarted3 then copy the 'ELSE IF NOT' section of the script?

0

Yes =)

0

Why does it keep repeating the first song over and over again?

0

in each statement stop all the music

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