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

How to stop music when I click the same music GUI text button?

So I made a functioning script to play music when I clicked a text button, but now I am struggling to know what to add to my script to make the music stop when I click the same button. Here's what I have so far!

local button = script.Parent

function playmusic() game.Workspace.Music.ArianaGrande7Rings:Stop()

game.Workspace.Music.ArianaGrande7Rings:Play()

end

button.Activated:Connect(playmusic)

1 comment

0

sorry, i missed the Gui part, but the code can work for a text button too

2 answers

ClickDetector.MouseClick:Connect(function()
		if game.Workspace.Music.ArianaGrande7Rings.IsPlaying == false then
		game.Workspace.Music.ArianaGrande7Rings:Play()
		else
		game.Workspace.Music.ArianaGrande7Rings:Stop()
end

hope this helped

local Button = script.Parent

local MusicIsPlaying = false

Button.MouseButton1Down:Connect(function()
	if MusicIsPlaying == false then
		MusicIsPlaying = true
		game.Workspace.Music.ArianaGrande7Rings:Play()
	elseif MusicIsPlaying == true then
		MusicIsPlaying = false
		game.Workspace.Music.ArianaGrande7Rings:Stop()
	end
end)

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