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

The audio is looped but won't stop when I need it to. Anyone know how to fix it?

Asked by 4 years ago

Basically I want this audio to be looped but when I click the button again, it stops. It isn't happening. Anybody know how to fix this?

script.Parent.MouseClick:connect (function(start)
script.Parent.Parent.Audio:Play()
script.Parent.MouseClick:connect (function(stop)
script.Parent.Parent.Audio:Stop()
end)
end)

2 answers

Log in to vote
2
Answered by 4 years ago

You're repeating the same event inside of the first. There's no reason to do this.

We can put just one event, and we can just do a check inside of it to see if the audio is playing, if it isn't then we play, but if it is we stop the audio.

script.Parent.MouseClick:Connect(function(start)
    local audio = script.Parent.Parent.Audio --//A variable to put our audio in so it's easier to reference it

    if (audio.IsPlaying == false) then --//It isn't playing so we start it
        audio:Play()
    elseif (audio.IsPlaying == true) then --//It is playing so we stop it
        audio:Stop()
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

This is what I personally use for my buttons. It sets the text of the TextButton to say "Music: On" or "Music: Off"

local button = script.Parent

button.MouseButton1Click:Connect(function()
    if button.Text == "Music: On" then
game.Workspace.music.Playing = false
        button.Text = "Music: Off"
    else
        game.Workspace.music.Playing = true

        button.Text = "Music: On"

    end
end)

Hope this helped! :)

Answer this question