Playing sound if GUI visible, otherwise destroying the sound

This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.

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!
    Whenever a part of a GUI or the GUI itself is visible I want it to play a sound, otherwise the sound should either stop or be destroyed.
  2. What is the issue? Include screenshots / videos if possible!
    I’ve tried multiple times and I think I am doing something wrong.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Nothing much, I just don’t know what to do
    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!
while true do
	if script.Parent.Parent.MainMenu.credits.Visible == true then
		script.MusicMain:Play()
	elseif script.Parent.Parent.MainMenu.credits.Visible == false then
		script.MusicMain:Destroy()
	end
end

Can I see your whole script please, I need more information about your script!!

script.Parent.Parent.MainMenu.credits:GetPropertyChangedSignal("Visible"):Connect(function()

if script.Parent.Parent.MainMenu.credits.Visible == true then

script.MusicMain:Play()

else

script.MusicMain:Stop()

end)
1 Like

Change the .Visible to .Enabled in the script!!

script.Parent.Parent.MainMenu.play.Visible:GetPropertyChangedSignal("Visible"):Connect(function()

	if script.Parent.Parent.MainMenu.play.Enabled == true then

		script.MusicMain:Play()

	else

		script.MusicMain:Stop()

	end
end)

that doesn’t look right

Send me a Screen of your Menu


I mean your Explorer in the Studio

image

script.MusicMain:Play()
script.Parent.Parent.MainMenu.play:GetPropertyChangedSignal("Visible"):Connect(function()

	if script.Parent.Parent.MainMenu.play.Visible == true then

		script.MusicMain:Play()

	else

		script.MusicMain:Stop()

	end
end)

It doesn’t play any sound. I’m sure everything’s put together. (I also own the sound, and I provided it permissions)
image

Check if the volume isn’t 0.

Also I’m not sure if sounds will only play under certain parents so try to parent the sound to the ScreenGUI and repath the script.

Also are there any errors?

No, there aren’t any other errors.