So far I have gotten my script to play audio at the push of a button. But I want it so when i press the button again it stops.
1 | local clickdetector = workspace.Lockdown.ClickDetector |
2 | clickdetector.MouseClick:Connect( function () |
3 | workspace.Lockdown.Sound:Play() |
4 | end ) |
5 | if workspace.Lockdown.Sound.Playing then |
6 | workspace.Lockdown.Sound:Pause() |
7 | end |
With kingdom5's answer i have this which still does not work
1 | local clickdetector = workspace.Lockdown.ClickDetector |
2 | clickdetector.MouseClick:Connect( function () |
3 | workspace.Lockdown.Sound:Play() |
4 | if workspace.Lockdown.Sound.IsPlaying then |
5 | workspace.Lockdown.Sound:Stop() |
6 | end |
7 | end ) |
Thank you for helping. The script now looks like this:
01 | local clickdetector = workspace.Music 0. Music 0 Brick.ClickDetector |
02 | clickdetector.MouseClick:Connect( function () |
03 | if workspace.Sound.Music 0. IsPlaying = = false then |
04 | workspace.Sound.Music 0 :Play() |
05 | workspace.Music 0. LightA.BrickColor = BrickColor.Red() |
06 | workspace.Music 0. LightB.BrickColor = BrickColor.Red() |
07 | repeat |
08 | script.Parent.BrickColor = BrickColor.new( "Br. yellowish green" ) |
09 | wait( 0.5 ) |
10 | script.Parent.BrickColor = BrickColor.new( "Eggplant" ) |
11 | wait( 0.5 ) |
12 | script.Parent.BrickColor = BrickColor.new( "Br. yellowish green" ) |
13 | until workspace.Sound.Music 0. IsPlaying = = false |
14 | else |
15 | workspace.Sound.Music 0 :Stop() |
16 | workspace.Music 0. LightA.BrickColor = BrickColor.Gray() |
17 | workspace.Music 0. LightB.BrickColor = BrickColor.Gray() |
18 | script.Parent.BrickColor = BrickColor.new( "Br. yellowish green" ) |
19 | end |
20 | end ) |
You would have to check the sound if it is playing first before actually playing it, otherwise when the sound plays, it’ll move on to the conditional statement and immediately stop it.
Here is how I would do it :
1 | local clickdetector = workspace.Lockdown.ClickDetector |
2 | clickdetector.MouseClick:Connect( function () |
3 | if workspace.Lockdown.Sound.IsPlaying = = false then |
4 | workspace.Lockdown.Sound:Play() |
5 | else |
6 | workspace.Lockdown.Sound:Stop() |
7 | end |
8 | end ) |
The script checks if the sound is playing or not. If not, it plays, otherwise it stops.