Sound keeps playing after entering the game!

  1. What do you want to achieve? Keep it simple and clear!
    I want the sound to stop playing after I click the play button, I also want to switch thru cams in the menu.
  2. What is the issue? Include screenshots / videos if possible!
    The sound keeps playing in game after clicking the play button.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried destroying the sound, stopping it, muting it… none of these seem to work!
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local fade = script.Parent.Fade
local music = script.Parent.Music
local start = script.Parent.Start

local TS = game:GetService("TweenService")
local ftween = TS:Create(fade, TweenInfo.new(5), {BackgroundTransparency = 1})
local ftween2 = TS:Create(fade, TweenInfo.new(2.5), {BackgroundTransparency = 0})

local musicstop = TS:Create(music, TweenInfo.new(1), {Volume = 0})


workspace.ambience.negativeambience:Pause()

local random = math.random(1,6)

local camera = workspace.camCFrames["cam"..random]
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = camera.CFrame

local respawnevent = game.ReplicatedStorage.Respawn

game:GetService("Players").LocalPlayer.CameraMaxZoomDistance = 15
game:GetService("Players").LocalPlayer.CameraMinZoomDistance = 15

repeat wait() until game:IsLoaded()

music:Play()
wait(2.5)
ftween:Play()

script.Parent.play.MouseButton1Click:Connect(function()
	musicstop:Play()
	start:Play()
	start.Ended:Wait()
	ftween2:Play()
	wait(5)
	game.SoundService.AmbientReverb = Enum.ReverbType.UnderWater
	game.Lighting.MenuBlur.Enabled = true
	fade.BackgroundTransparency = 1
	script.Parent.Loading.Visible = true
	script.Parent.Title.Visible = false
	script.Parent.play.Visible = false
	script.Parent.credits.Visible = false
	script.Parent.settings.Visible = false
	music.Playing = false
	wait(10)
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.SoundService.AmbientReverb = Enum.ReverbType.ParkingLot
	game.Lighting.MenuBlur.Enabled = false
	workspace.ambience.negativeambience:Resume()
	respawnevent:FireServer(game.Players.LocalPlayer)
	script.Parent:Destroy()
	end)

I think you got enabled the PlayOnRemove property of the sound, so it plays after getting destroyed

Just checked, that is disabled.

I also have a localscript inside that localscript that switches between the cams,

while true do
	local random = math.random(1,6)
	local camera = workspace.camCFrames["cam"..random]
	workspace.CurrentCamera.CFrame = camera.CFrame
	wait(5)
end

interesting issue, i believe your issue might be the tween service? i’ve never seen that type of way to stop music before. it might be easier to just give up on a smooth transition out of music and just do

music:Stop()

again i believe your issue is with how you try to tween the volume to 0.

I have tried putting music:Stop() at the script.Parent.play.MouseButton1Click:Connect(function() but that did not seem to work either.

what i was saying was to replace the musicstop:Play() with just plain old music:Stop()

I did,

local fade = script.Parent.Fade
local music = script.Parent.Music
local start = script.Parent.Start

local TS = game:GetService("TweenService")
local ftween = TS:Create(fade, TweenInfo.new(5), {BackgroundTransparency = 1})
local ftween2 = TS:Create(fade, TweenInfo.new(2.5), {BackgroundTransparency = 0})

-- local musicstop = TS:Create(music, TweenInfo.new(1), {Volume = 0})


workspace.ambience.negativeambience:Pause()

local random = math.random(1,6)

local camera = workspace.camCFrames["cam"..random]
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = camera.CFrame

local respawnevent = game.ReplicatedStorage.Respawn

game:GetService("Players").LocalPlayer.CameraMaxZoomDistance = 15
game:GetService("Players").LocalPlayer.CameraMinZoomDistance = 15

repeat wait() until game:IsLoaded()

music:Play()
wait(2.5)
ftween:Play()

script.Parent.play.MouseButton1Click:Connect(function()
	music:Stop()
	start:Play()
	start.Ended:Wait()
	ftween2:Play()
	wait(5)
	game.SoundService.AmbientReverb = Enum.ReverbType.UnderWater
	game.Lighting.MenuBlur.Enabled = true
	fade.BackgroundTransparency = 1
	script.Parent.Loading.Visible = true
	script.Parent.Title.Visible = false
	script.Parent.play.Visible = false
	script.Parent.credits.Visible = false
	script.Parent.settings.Visible = false
	music.Playing = false
	wait(10)
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.SoundService.AmbientReverb = Enum.ReverbType.ParkingLot
	game.Lighting.MenuBlur.Enabled = false
	workspace.ambience.negativeambience:Resume()
	respawnevent:FireServer(game.Players.LocalPlayer)
	script.Parent:Destroy()
	script.Parent.Music:Destroy()
end)

are you experiencing any errors in output?
does everything else in the function work?

and finally, can you send a screenshot of the music’s properties as well as ( if you can ) a video of what happens when you press play?

i should have asked this first but i just was hoping for an easier solution.

I don’t see any errors in the output,
everything else works but that specific thing.

image
image
image

Maybe… because the character spawns again after pressing the play button and the music keeps is playing? only do music:Play() when the player is in the loading screen, not in the actual game

How would that be done? Do I destroy the music just right before the end of the whole script?

set looped to false before doing stop
something like

music.Looped = false
music:Stop()

edit: isn’t the issue, as MOVISTAR said it’s because the character reloads


another issue here, you might wanna not destroy the script.Parent and all that

The issue is that the Looped property is already enabled before running the game, so whenever your character is (re)spawned, the sound will automatically play. You have to disable the Looped property manually, not in a script.
After you disable Loooped, you may still tween the volume of the sound if you’d like, but you need to play the sound when the player first joins.

Can i add music.Looped before the script.Parent.play.MouseButton1Click:Connect(function()?

Yes, you may set the Looped property to true in the script, no problem. Just keep the Looped property set to false from the properties tab before running the game.

I tested this script and it did not seem to work, it still played music. Could you tell me what’s wrong?

local fade = script.Parent.Fade
local music = script.Parent.Music
local start = script.Parent.Start

local TS = game:GetService("TweenService")
local ftween = TS:Create(fade, TweenInfo.new(5), {BackgroundTransparency = 1})
local ftween2 = TS:Create(fade, TweenInfo.new(2.5), {BackgroundTransparency = 0})

local musicstop = TS:Create(music, TweenInfo.new(1), {Volume = 0})


workspace.ambience.negativeambience:Pause()

local random = math.random(1,6)

local camera = workspace.camCFrames["cam"..random]
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = camera.CFrame

local respawnevent = game.ReplicatedStorage.Respawn

game:GetService("Players").LocalPlayer.CameraMaxZoomDistance = 15
game:GetService("Players").LocalPlayer.CameraMinZoomDistance = 15

repeat wait() until game:IsLoaded()

music:Play()
wait(2.5)
ftween:Play()
music.Looped = true
script.Parent.play.MouseButton1Click:Connect(function()
	musicstop:Play()
	start:Play()
	start.Ended:Wait()
	ftween2:Play()
	wait(5)
	game.SoundService.AmbientReverb = Enum.ReverbType.UnderWater
	game.Lighting.MenuBlur.Enabled = true
	fade.BackgroundTransparency = 1
	script.Parent.Loading.Visible = true
	script.Parent.Title.Visible = false
	script.Parent.play.Visible = false
	script.Parent.credits.Visible = false
	script.Parent.settings.Visible = false
	music.Playing = false
	wait(10)
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.SoundService.AmbientReverb = Enum.ReverbType.ParkingLot
	game.Lighting.MenuBlur.Enabled = false
	workspace.ambience.negativeambience:Resume()
	respawnevent:FireServer(game.Players.LocalPlayer)
	script.Parent:Destroy()
	script.Parent.Music:Destroy()
end)

So just to be clear, the sound does stop playing when you click the button, but when you respawn, the sound will start playing again, is that correct? If so, I believe this is because this script continues to run even after respawning, which even runs the music.Looped = true code line.
I think you need to find a way to disable the script, or find a way to check if the player is currently in the menu or not.
If you have something to check if the player is in the menu or not, make an if statement to check if the player is currently in menu, then it will set Looped to true, and vice versa.

Yes, the the music stops playing upon clicking the button, the fade in and out animation happens and then it plays it again.

Also I do not think I am capable of that, I am not too experienced.