Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I made this music mute button and its not working. No errors. Help?

I get no errors or anything. When I click to mute it nothing happens. Please help!

local MusicPlaying = game.Players.LocalPlayer:WaitForChild("MusicPlaying")

local LobbyMusic = workspace.LobbyMusic:GetChildren()

local GameMusic = workspace.LobbyMusic:GetChildren()

while true do
	wait()
if MusicPlaying == true then
	wait(0.05)
	for key, v in next, LobbyMusic do
		print(v.LobbyMusic)
		if v.IsA("Sound") then
			print(v.Sound)
			v.Stop()
			end
		end
	end
end

while true do
	wait()
if MusicPlaying == true then
	wait(0.05)
	for key, v in next, GameMusic do
		if v.IsA("Sound") then
			v.Stop()
			end
		end
	end
end

1 comment

0

Is this in a local or server script?

1 answer

✓ Accepted answer

I think the problem is that you forgot to write .Value after MusicPlaying. Try this:

local MusicPlaying = game.Players.LocalPlayer:WaitForChild("MusicPlaying")

local LobbyMusic = workspace.LobbyMusic:GetChildren()

local GameMusic = workspace.LobbyMusic:GetChildren()

while true do
    wait()
if MusicPlaying.Value == true then
    wait(0.05)
    for key, v in ipairs(LobbyMusic) do
        print(v.LobbyMusic)
        if v.IsA("Sound") then
            print(v.Sound)
            v.Stop()
            end
        end
    end
end

coroutine.wrap(function()
	local MusicPlaying = game.Players.LocalPlayer:WaitForChild("MusicPlaying")
	
	local LobbyMusic = workspace.LobbyMusic:GetChildren()
	
	local GameMusic = workspace.LobbyMusic:GetChildren()

	while true do
		    wait()
		if MusicPlaying.Value == true then
		    wait(0.05)
		    for key, v  in ipairs(GameMusic) do
		        if v.IsA("Sound") then
		            v.Stop()
		            end
		        end
		    end
		end
end)()

Also, I used ipairs instead of next.

5 comments

0

I have a question how did you know that coroutine.yeild would do the trick Did you search it up?

0

What do you mean by corooutine.yeild? Do you mean coroutine.wrap?

0

I meant coroutine.wrap

0

I already had learned what coroutine did.

1

A while true do loop will keep on looping and never go to the rest of the script unless you break it. A coroutine will prevent that as the code inside it's scope doesn't prevent the code outside of it from running.

This discussion is preserved as it was. New answers, comments, and votes are closed.