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

Any help for this music script?

Hi,

I have two scripts here that work fine. I press play and it plays but when I stop one and press play on the other button with the other script the music from before starts playing again.

Say; I press script 1 button. Summer comes on, then I click the button again for it to stop and it all stops. Then I press script 2 button and Let it go comes on, then a couple of seconds later Summer or another song in my workspace comes on with let it go!

Please help!

Here are the two scripts.

Script one;

local Clicked = false
 
function onClick()
    Clicked = not Clicked
script.Parent.BrickColor = BrickColor.new("Really red") -- Same here
    while Clicked do
        script.Parent.Parent.Sound7:Play()
        wait(120)
        script.Parent.Parent.Sound7:Stop()
        wait(.1)
        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)
    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)

Script 2;

local Clicked = false
 
function onClick()
    Clicked = not Clicked
script.Parent.BrickColor = BrickColor.new("Really red") -- Same here
    while Clicked do
        script.Parent.Parent.Sound6:Play()
        wait(120)
        script.Parent.Parent.Sound6:Stop()
        wait(.1)
        script.Parent.Parent.Sound7:Play()
        wait(120)
        script.Parent.Parent.Sound7:Stop()
        wait(.1)
        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)
    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)

Thanks Kieran

2 answers

✓ Accepted answer

I think your problem is that you are using if not Clicked, while you should be using if Clicked == false. You have set the Clicked variable to false, but then 3 lines later you set it to the opposite of Clicked, meaning true. It is a very sketchy debounce, if you ask me. Try replacing lines 4, 6, and 37 with Clicked having a conditional argument, rather than what you did. Do the same for the 2nd script.

local Clicked = false

function onClick()
    if Clicked == false then
	Clicked = true
script.Parent.BrickColor = BrickColor.new("Really red") -- Same here
   --Removed the while line that was here
        script.Parent.Parent.Sound7:Play()
        wait(120)
        script.Parent.Parent.Sound7:Stop()
        wait(.1)
        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)

    elseif Clicked == true then
	Clicked = false
    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 comments

0

Please look at my answer below to see if it is right

0

Thank you!!!

So would this be right?

local Clicked = false

function onClick()
    Clicked = false
script.Parent.BrickColor = BrickColor.new("Really red") -- Same here
    while Clicked == true do
        script.Parent.Parent.Sound7:Play()
        wait(120)
        script.Parent.Parent.Sound7:Stop()
        wait(.1)
        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)
    end

    if Clicked == false 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)

1 comment

0

No, change line 4 to "Clicked = true". Then remove the "while Clicked == true do". I've edited my answer to include this corrected code.

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