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

The audio is looped but won't stop when I need it to. Anyone know how to fix it?

Basically I want this audio to be looped but when I click the button again, it stops. It isn't happening. Anybody know how to fix this?

script.Parent.MouseClick:connect (function(start)
script.Parent.Parent.Audio:Play()
script.Parent.MouseClick:connect (function(stop)
script.Parent.Parent.Audio:Stop()
end)
end)

2 answers

✓ Accepted answer

You're repeating the same event inside of the first. There's no reason to do this.

We can put just one event, and we can just do a check inside of it to see if the audio is playing, if it isn't then we play, but if it is we stop the audio.

script.Parent.MouseClick:Connect(function(start)
	local audio = script.Parent.Parent.Audio --//A variable to put our audio in so it's easier to reference it
	
	if (audio.IsPlaying == false) then --//It isn't playing so we start it
		audio:Play()
	elseif (audio.IsPlaying == true) then --//It is playing so we stop it
		audio:Stop()
	end
end)

This is what I personally use for my buttons. It sets the text of the TextButton to say "Music: On" or "Music: Off"

local button = script.Parent

button.MouseButton1Click:Connect(function()
	if button.Text == "Music: On" then
game.Workspace.music.Playing = false
		button.Text = "Music: Off"
	else
		game.Workspace.music.Playing = true

		button.Text = "Music: On"

	end
end)

Hope this helped! :)

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