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

Need help making an audio script start and stop audio?

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.

local clickdetector = workspace.Lockdown.ClickDetector
clickdetector.MouseClick:Connect(function()
	workspace.Lockdown.Sound:Play()
end)
if workspace.Lockdown.Sound.Playing then
	workspace.Lockdown.Sound:Pause()
end


With kingdom5's answer i have this which still does not work

local clickdetector = workspace.Lockdown.ClickDetector
clickdetector.MouseClick:Connect(function()
    workspace.Lockdown.Sound:Play()
	if workspace.Lockdown.Sound.IsPlaying then
    workspace.Lockdown.Sound:Stop()
end
end)



Thank you for helping. The script now looks like this:

local clickdetector = workspace.Music0.Music0Brick.ClickDetector
clickdetector.MouseClick:Connect(function()
    if workspace.Sound.Music0.IsPlaying == false then
        workspace.Sound.Music0:Play()
		workspace.Music0.LightA.BrickColor=BrickColor.Red()
		workspace.Music0.LightB.BrickColor=BrickColor.Red()
		repeat
			script.Parent.BrickColor=BrickColor.new("Br. yellowish green")
			wait(0.5)
			script.Parent.BrickColor=BrickColor.new("Eggplant")
			wait(0.5)
			script.Parent.BrickColor=BrickColor.new("Br. yellowish green")
		until workspace.Sound.Music0.IsPlaying == false
    else
        workspace.Sound.Music0:Stop()
		workspace.Music0.LightA.BrickColor=BrickColor.Gray()
		workspace.Music0.LightB.BrickColor=BrickColor.Gray()
		script.Parent.BrickColor=BrickColor.new("Br. yellowish green")
    end
end)

3 comments

0

You just need to put the if statment inside the function if Sound.Playing then -- play esle -- pause end

0

also, how would i make the sound play through the whole map?

0

Kingdom5 did not work.

1 answer

✓ Accepted answer

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 :

local clickdetector = workspace.Lockdown.ClickDetector
clickdetector.MouseClick:Connect(function()
    if workspace.Lockdown.Sound.IsPlaying == false then
        workspace.Lockdown.Sound:Play()
    else
        workspace.Lockdown.Sound:Stop()
    end
end)

The script checks if the sound is playing or not. If not, it plays, otherwise it stops.

1 comment

0

thank you

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