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 7 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.

Brick = script.Parent
Sound = Brick.Sound

function onClicked()
Sound:Play()
script.Parent.Value.Value = true
end

function onClicked()
if script.Parent.Value.Value = true then
Sound:Stop()
else
end

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

2 answers

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

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

script.Parent.ClickDetector.MouseClick:Connect(function()
    if Sound.IsPlaying then
        Sound:Stop() -- or Sound:Pause()
    else
        Sound:Play() -- or Sound:Resume()
    end
end)

0
Sad Violin... :( AlphaGamer150 101 — 7y
0
thank you for being nice and my friend EpicalAgent56 5 — 7y
0
i had to change where it says sound to script.Parent.Sound EpicalAgent56 5 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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

script.Parent.ClickDetector.MouseClick:connect(function()
    if script.Parent.Value.Value == false then
        script.Parent.Sound:Play()
        script.Parent.Value.Value = true
    else
        script.Parent.Sound:Stop()
        script.Parent.Value.Value = false
    end
end)
0
If this answer helped, please click 'Accept Answer' below. AlphaGamer150 101 — 7y

Answer this question