Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

There isn't an error in the output, but this script is supposed to mute music but it doesn't?

Asked by 7 years ago
local enabled = true

function onClick(clicked)
    local backgroundmusic = script.Parent.Parent.Parent:WaitForChild('TopBar'):FindFirstChild('Music')

            if enabled == true then
                if backgroundmusic then
                    backgroundmusic.Volume = 0
                    enabled = false
                    script.Parent.Text = 'Music: OFF'
                else
                    enabled = false
                    script.Parent.Text = 'Music: OFF'
                    while wait(1) do
                        if script.Parent.Parent.Parent:WaitForChild('TopBar'):FindFirstChild('Music') then
                            backgroundmusic.Volume = 0
                            break   
                    end
                end

            if enabled == false then
                if backgroundmusic then
                    backgroundmusic.Volume = 0.5
                    enabled = true
                    script.Parent.Text = "Music: ON"
                else
                    enabled = true
                    script.Parent.Text = "Music: ON"
                    while wait(1) do
                        if backgroundmusic then
                            backgroundmusic.Volume = 0.5
                            break
                            end
                        end
                    end
                end                 
            end
        end
    end

script.Parent.MouseButton1Click:connect(onClick)

It works when you click it the first time, but when you try and turn the music back on, it doesn't work. Any ideas why?

0
There is a option to pause music. :Pause(). Also why do you need to break a loop and the function? User#18043 95 — 7y

Answer this question