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

Music script doesn't work. Why? [closed]

Asked by 8 years ago

Hi!

I have made a music script for one of my games and it works, except for one thing. Even if the music is told to be off, it still plays the next song! I have put in a lot of code to prevent this but it still happens. I don't know why. Here is the code:

playing = false

     local s1 = script.Parent.Parent.song
    local s2 = script.Parent.Parent.song2
    local s3 = script.Parent.Parent.song3
    local s4 = script.Parent.Parent.song4



    script.Parent.MouseButton1Down:connect(function()

        if playing == false then -- check if audio is playing

            playing = true -- allow the script to know if its on or not

            script.Parent.Text = "Music: On" -- change the name like you wanted

                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()   
                wait(0.5)       

            s1:Play() -- play all the music

                wait(120)
    if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    end

                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()

    wait(1)
if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    end
                s2:Play()

                wait(106.371)
    if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()

    end

                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    wait(1)
if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    end
                 s3:Play()

                 wait(101)
    if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    end

                 s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    wait(1)
    if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    end

                s4:Play()

                wait(76)
    if script.Parent.Text == "Music: Off" then
                s1:Stop()
                s2:Stop()
                s3:Stop()
                s4:Stop()
    end

                s4:Stop()
    wait(0.1)
    script.Parent.Text = "Music: Off"

        else -- if audio is playing we want to stop it

            playing = false


                s1:Stop()

                s2:Stop()

               s3:Stop()

               s4:Stop()

               script.Parent.Text = "Music: Off"

        end

    end)

Closed as Not Constructive by Shawnyg

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?