Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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)

0
sorry, i missed the Gui part, but the code can work for a text button too aprilsfooled 29 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
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

Ad
Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
4 years ago
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)

Answer this question