Music not stopping when running :stop()

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make it so when I run sfxfolder.Ambiance:Stop() it stops the Ambiance sound.

  2. What is the issue? Include screenshots / videos if possible!
    There are no errors, but the sound does not stop, and it keeps playing.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried enabling/disabling loop (as you can see in the script), that didn’t do much.

script.Value.Value = 0
sfxfolder = script.Parent.Parent.Parent.Parent.SoundEffects

function check()
 if script.Value.Value == 0 then
  script.Parent.Enabled.Visible = false
  sfxfolder.Ambiance.Looped = false
  sfxfolder.Ambiance:Stop()
  script.Parent.Disabled.Visible = true
  wait(0.1)
  script.Value.Value = 1
 else
  script.Parent.Enabled.Visible = true
  sfxfolder.Ambiance.Looped = true
  sfxfolder.Ambiance:Play()
  script.Parent.Disabled.Visible = false
  wait(0.1)
  script.Value.Value = 0
 end
end

script.Parent.MouseButton1Click:Connect(check)

The weird thing is, though, the script.Parent.Disabled.Visible = false and script.Parent.Enabled.Visible = false work, even though they’re after the sfxfolder.Ambiance:Stop()

Are you sure the Stop is being called? I’d add a print somewhere in the stops if to see if it is ever being ran.

Yeah, it does get called. 30characters

Are you doing this on the server, or client?

I’m running it on the client. 30char

Weird, I’m way too sleepy to think this over tonight. Maybe someone else can help you out. I’m going to go to bed :eye:

on another note do you need to disable looped?

sfxfolder.Ambiance.Looped = false

once it is started, shouldn’t it stop when you fire stop?

I thought that the looped might be causing an issue so I added that in case it was.

So, are you trying to pause the audio at a certain time and then resume it again? If that’s the case, use :Pause() and :Resume()

The issue I’m having is that it won’t stop at all when the function is fired. (when it’s fired, the sound will continue playing) There’s no errors, either, and I did a print test and the test came back successfully. It’s an ambiance loop so I don’t need to pause/resume it.

Could I see the explorer of everything that is defined in the script? That’s probably the problem.

1 Like

Quite a tricky problem, If the control flow is getting to that statement I’m not sure why its not working. But try this code out and see if it behaves any differently.

local switch=false
local sound=script.Parent.Parent.Parent.Parent.SoundEffects.Ambiance

if not sound.IsLoaded then
	sound.Loaded:Wait()
end

local function toggleMusic()
	if not switch then
		sound:Play()
	else
		sound:Stop()
	end
	wait(.1)
	switch= not switch
end

script.Parent.MouseButton1Click:Connect(toggleMusic)

I’ve had a similar problem and I just destroyed the sound in that seemed to work

No dice with that one, now it doesn’t even change the text.

I got it working, here’s the functional script:

	script.Parent.Parent.Parent.Parent.SoundEffects.ClickSound:Play()
	if script.Parent.bruh.Value == false then 
		script.Parent.Parent.Parent.Parent.LoadingFrame.Sound:Pause()
		script.Parent.Enabled.Visible = false
		script.Parent.Disabled.Visible = true
		script.Parent.bruh.Value = true
	else
		script.Parent.Parent.Parent.Parent.LoadingFrame.Sound:Resume()
		script.Parent.Enabled.Visible = true
		script.Parent.Disabled.Visible = false
		script.Parent.bruh.Value = false
	end
end)

script.Parent.MouseEnter:Connect(function()
	script.Parent.Parent.Parent.Parent.SoundEffects.HoverSound:Play()
end)