Music system help

Recently I decided to do my own music system, but I ran into a problem.
When a player turns on the music, dies, goes to settings, and turns it on again - there will be 2 music playing at the same time.
Here’s my script:

button.MouseButton1Click:Connect(function()	
	if started == false and on == false then
		on = true
		started = true

		randomSound()
		button.ImageColor3 = Color3.fromRGB(255, 255, 255)
		
	elseif started == true and on == false then
			
		on = true
		
		game.SoundService[v]:Resume()
		button.ImageColor3 = Color3.fromRGB(255, 255, 255)
		
	elseif on == true then
		
		on = false
		
		game.SoundService[v]:Pause()
		
		button.ImageColor3 = Color3.fromRGB(0, 0, 0)
	end
end)

Video: https://gyazo.com/58144b5e51d48458585f9b0fb476c075

Do you have ResetOnSpawn set to true, if you do set it to false.

2 Likes

I think that’s because your script is connected to character or, most likely, GUI reset as aforementioned. Both resets the variable of the script upon refresh.

2 Likes