I am using a boolvalue and a sound and a clickdetector. I am trying to make it so when I press the siren [i am making a police car] a siren sound plays. I got the script as a free model but i had to edit it since it meant that I could only play it not stop / pause it.
01 | Brick = script.Parent |
02 | Sound = Brick.Sound |
03 |
04 | function onClicked() |
05 | Sound:Play() |
06 | script.Parent.Value.Value = true |
07 | end |
08 |
09 | function onClicked() |
10 | if script.Parent.Value.Value = true then |
11 | Sound:Stop() |
12 | else |
13 | end |
14 |
15 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
here is the hierachy Part Sound Clickdetector Value (boolvalue) Script
The worst thing for me is that I cannot find any decent place to help me start learning to script! thanks
it can be done a lot easier by doing a check on the IsPlaying property
1 | script.Parent.ClickDetector.MouseClick:Connect( function () |
2 | if Sound.IsPlaying then |
3 | Sound:Stop() -- or Sound:Pause() |
4 | else |
5 | Sound:Play() -- or Sound:Resume() |
6 | end |
7 | end ) |
I don't know weather this helps, but try this:
1 | script.Parent.ClickDetector.MouseClick:connect( function () |
2 | if script.Parent.Value.Value = = false then |
3 | script.Parent.Sound:Play() |
4 | script.Parent.Value.Value = true |
5 | else |
6 | script.Parent.Sound:Stop() |
7 | script.Parent.Value.Value = false |
8 | end |
9 | end ) |