You can write your topic however you want, but you need to answer these questions:
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.
What is the issue? Include screenshots / videos if possible!
There are no errors, but the sound does not stop, and it keeps playing.
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()
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.
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)