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

How to use a boolvalue with turning a sound on and off?

Asked by 8 years ago

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.

01Brick = script.Parent
02Sound = Brick.Sound
03 
04function onClicked()
05Sound:Play()
06script.Parent.Value.Value = true
07end
08 
09function onClicked()
10if script.Parent.Value.Value = true then
11Sound:Stop()
12else
13end
14 
15script.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

2 answers

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

it can be done a lot easier by doing a check on the IsPlaying property

1script.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
7end)
0
Sad Violin... :( AlphaGamer150 101 — 8y
0
thank you for being nice and my friend EpicalAgent56 5 — 8y
0
i had to change where it says sound to script.Parent.Sound EpicalAgent56 5 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

I don't know weather this helps, but try this:

1script.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
9end)
0
If this answer helped, please click 'Accept Answer' below. AlphaGamer150 101 — 8y

Answer this question