I made a script to play music. Problem is, whenever the player resets, another song starts playing in addition to the old one. My LocalScript in StarterGui:

SoundFolder = game.Workspace.SoundFolder

local Songs = SoundFolder.BGM:GetChildren()

print (Songs)

local CurrentSong = Songs[math.random(1,#Songs)]

print (CurrentSong)

local SongLength = CurrentSong.TimeLength

CurrentSong:Play()
SoundFolder.Wind:Stop()

game.ReplicatedStorage.Status.Changed:Connect(function(newstring)
    if newstring == "Game in progress." then
		for i, song in pairs(Songs) do
			song:Stop()
		end
		SoundFolder.Wind:Play()
		SoundFolder.Warning:Play()
    elseif newstring == "The game has ended! Initializing cleanup." then
		for i, song in pairs(Songs) do
			song:Stop()
		end
		CurrentSong = Songs[math.random(1,#Songs)]
		CurrentSong:Play()
		SoundFolder.Wind:Stop()
		SoundFolder.Warning:Stop()
    elseif newstring == "Waiting for players." then
		for i, song in pairs(Songs) do
			song:Stop()
		end
		CurrentSong = Songs[math.random(1,#Songs)]
		CurrentSong:Play()
		SoundFolder.Wind:Stop()
		SoundFolder.Warning:Stop()
    end
end)

2 comments

0

You probably have the PlayOnRemove property ticked on the Sound.

0

No, it is off.