How to Make Music Come Back After Coming Back to Main Menu

I wanted the music to play when I open menu back but it doesn’t play.


I tried using the infinite loop but I didn’t know how to do it?

-- MusicScript, also a LocalScript, this is not combined with the other LocalScript
music = script.Parent.MenuMusic
Button = script.Parent.Deploy
music:Play()
Button.MouseButton1Click:Connect(function()
    music:Stop()
end)

-- Local Script
script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.MainMenu.Visible = true
end)

while true do
	music = script.Parent.MenuMusic
	music = script.Parent.Parent.MainMenu 
	music:Play()
	script.Parent.MouseButton1Click:Connect(function()
		music:Stop()
	end)
end

LocalScript is combined with OpenMenuGui shown in the vid. MusicScript is with the MainMenu. I use the Deploy Button to get out of the menu and I use the Open Menu Button to get back in the Menu.

1 Like

I forgot to put – LocalScript to know which script it was, bruh, sorry. Also the MusicScript is a LocalScript as well.

script.Parent.MouseButton1Click:Connect(function() 
     menu.Enabled = not menu.Enabled --initially true
     music.Playing = not music.Playing --initially true
end

Do I put this in the MusicScript or LocalScript? Do I keep my infinite loop in the script? Check the edit of my post if you didn’t know which one was LocalScript or MusicScript. Oh I forgot to say the LocalScript is combined with the OpenMenuGui shown in the vid.

Remove the button connection block and the music:Stop() from the music script, and let the localscript toggle the music and menu both! You can also remove the while true do loop, as the new connection function I supplied will toggle it every time you press the button. Essentially, you’re letting the server script play the music and enable the menu. Then the localscript toggles both locally! Sorry for the confusion, both should be initially true.

I forgot to say the MusicScript is also a LocalScript. When I added it, it isn’t working because the music isn’t stopping and I can’t open back the open menu button. I forgot to say I use the Deploy Button to get out of the menu, and then I use the Open Menu Button to get back into the Menu. Here is the LocalScript.

Space

–LocalScript, not combined with the DeployLocalScript
local menu = script.Parent.Parent.OpenMenuGui
local music = script.Parent.MenuMusic
script.Parent.MouseButton1Click:Connect(function()

ddddmenu.Enabled = not menu.Enabled --initially true

ddddmusic.Playing = not music.Playing --initially true
end)

Space

–DeployLocalScript
script.Parent.MouseButton1Click:Connect(function()

dddd script.Parent.Parent.Visible = false
end)

 -- menu/music localscript
local menu = script.Parent.Parent.OpenMenuGui
local music = script.Parent.MenuMusic
menu.Enabled = true
music:Play()
script.Parent.MouseButton1Click:Connect(function()
     menu.Enabled = not menu.Enabled --initially true
     music.Playing = not music.Playing --initially true
end)

-- deploy localscript
local music = menumusicscript.Parent.MenuMusic
script.Parent.MouseButton1Click:Connect(function() 
     script.Parent.Parent.Enabled = false
     music.Playing = false
end)

The DeployLocalScript isn’t working because I can’t deploy, the menu isn’t going away.

try changing music.Playing to an if statement where

if music.Playing then
     music:Stop()
else
     music:Play()
end

Still not working, the menu is still there. Forgot to say I put the DeployButton in the MainMenu, the MainMenu is inside MenuGui, and I put the Open Menu Button in the MenuGui.

Can you screenshot the ancestry tree for me?

What is that? I think this is what you meant.
IdkPic

1 Like
 -- menu/music localscript
local menu = script.Parent.Parent.OpenMenuGui
local music = script.Parent.MenuMusic
menu.Enabled = true
music:Play()
script.Parent.MouseButton1Click:Connect(function()
     menu.Enabled = not menu.Enabled --initially true
     music.Playing = not music.Playing --initially true
end)

-- deploy localscript
local music = script.Parent.Parent.MenuMusic
script.Parent.MouseButton1Click:Connect(function() 
     script.Parent.Parent.Enabled = false -- edit is here from 3 parents to 2!
     music:Pause()
end)

We’re almost close. The menu is gone that’s good but the open menu button is gone.

1 Like

just rrefer to the mainmenu frame

Are you setting it’s visibility to false?

Also for future reference, rather than looping the music from the script itself, just go to properties and tick looped :wink:

No, do you mean the button? character

Yes the button that takes you back to the menu, is it’s visibility being marked as false?
If not then is the ScreenGui that houses the button being disabled?

I did and I couldn’t get out of the main menu.