Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

3 comments

0

Sad Violin... :(

0

thank you for being nice and my friend

0

i had to change where it says sound to script.Parent.Sound

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)

1 comment

0

If this answer helped, please click 'Accept Answer' below.

This discussion is preserved as it was. New answers, comments, and votes are closed.