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

How to stop music continuing after button pressed?

Asked by 6 years ago

Hi,

I am trying to get this script (which I made a long while ago) to stop and start music, which it half does. When I press to turn off, the music stops, but then after a while music continues again?

Anyone know how to stop the music altogether?

local Clicked = false

function onClick()
    Clicked = not Clicked
script.Parent.BrickColor = BrickColor.new("Really red") -- Same here
    while Clicked do
        script.Parent.Parent.Sound1:Play()
        wait(120)
        script.Parent.Parent.Sound1:Stop()
        wait(.1)
        script.Parent.Parent.Sound2:Play()
        wait(120)
        script.Parent.Parent.Sound2:Stop()
        wait(.1)
        script.Parent.Parent.Sound3:Play()
        wait(120)
        script.Parent.Parent.Sound3:Stop()
        wait(.1)
        script.Parent.Parent.Sound4:Play()
        wait(120)
        script.Parent.Parent.Sound4:Stop()
        wait(.1)
        script.Parent.Parent.Sound5:Play()
        wait(120)
        script.Parent.Parent.Sound5:Stop()
        wait(.1)
        script.Parent.Parent.Sound6:Play()
        wait(120)
        script.Parent.Parent.Sound6:Stop()
        wait(.1)
        script.Parent.Parent.Sound7:Play()
        wait(80)
        script.Parent.Parent.Sound7:Stop()
        wait(.1)
    end

    if not Clicked then
    script.Parent.BrickColor = BrickColor.new("Medium stone grey")
        script.Parent.Parent.Sound1:Stop()
        script.Parent.Parent.Sound2:Stop()
        script.Parent.Parent.Sound3:Stop()
        script.Parent.Parent.Sound4:Stop()
        script.Parent.Parent.Sound5:Stop()
        script.Parent.Parent.Sound6:Stop()
script.Parent.Parent.Sound7:Stop()
    end
end


script.Parent.ClickDetector.MouseClick:connect(onClick)
2
The music is properly stopping,  but the problem is that another music will start because of Lines 7-34. Even if you stop music, the script will keep going causing the other musics to eventually play. BloxRoxe 109 — 6y
0
So you are saying to stop the script from operating altogether? How would I go about this? kieranm9090 49 — 6y
1
You don't have to stop it all together, but make some sort of identifier that checks the Clicked value each time so that when you click the brick again, the next sound wont play. BloxRoxe 109 — 6y
0
Just disable the script, ez. Fixer1987 95 — 6y

1 answer

Log in to vote
1
Answered by
BloxRoxe 109
6 years ago
Edited 6 years ago

Basically, you can just check after each song if the Clicked value is still true. You can do this by adding an if statement to check the value.

while Clicked do
    if Clicked then
        script.Parent.Parent.Sound1:Play()
        wait(120)
        script.Parent.Parent.Sound1:Stop()
        wait(.1)
        if Clicked then
                -- repeat the code for each song
        end
    end
end

This is a very simple way, but it works.

Ad

Answer this question