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

Any help on what to put into this script?

Asked by 10 years ago

Ok so basically I want something simple to go into this script so that I press the button and it plays. Then if I press it again, it stop all the music. Here is the script that I created.

function onClick()
    while true 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)
    end
end


script.Parent.ClickDetector.MouseClick:connect(onClick)

Any help on this? Thanks Kieran

1 answer

Log in to vote
1
Answered by
Tiranin 45
10 years ago

Try this:

local Clicked = false

function onClick()
    Clicked = not Clicked
    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)
    end

    if not Clicked then
        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()
    end
end


script.Parent.ClickDetector.MouseClick:connect(onClick)


In theory it should work.

What it does is that when the player click the ClickDetector, the "Clicked" becomes either true or false based on its pervious value. If "Clicked" becomes true, it plays the while loop until it becomes false, and when it becomes false it stops all the music.

1
Thanks so much! Works perfectly. Thanks for your time!! kieranm9090 49 — 10y
Ad

Answer this question