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?
1 | script.Parent.MouseClick:connect ( function (start) |
2 | script.Parent.Parent.Audio:Play() |
3 | script.Parent.MouseClick:connect ( function (stop) |
4 | script.Parent.Parent.Audio:Stop() |
5 | end ) |
6 | end ) |
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.
1 | script.Parent.MouseClick:Connect( function (start) |
2 | local audio = script.Parent.Parent.Audio --//A variable to put our audio in so it's easier to reference it |
3 |
4 | if (audio.IsPlaying = = false ) then --//It isn't playing so we start it |
5 | audio:Play() |
6 | elseif (audio.IsPlaying = = true ) then --//It is playing so we stop it |
7 | audio:Stop() |
8 | end |
9 | end ) |
This is what I personally use for my buttons. It sets the text of the TextButton to say "Music: On" or "Music: Off"
01 | local button = script.Parent |
02 |
03 | button.MouseButton 1 Click:Connect( function () |
04 | if button.Text = = "Music: On" then |
05 | game.Workspace.music.Playing = false |
06 | button.Text = "Music: Off" |
07 | else |
08 | game.Workspace.music.Playing = true |
09 |
10 | button.Text = "Music: On" |
11 |
12 | end |
13 | end ) |
Hope this helped! :)