Music gui settings not working

i tried to make a mute and unmute music but i failed here:

local music = game.SoundService.music

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Text == "ON" then
		script.Parent.Text = "OFF"
		music.Playing = false
	else
		script.Parent.Text = "ON"
		music.Playing = true
	end
end)

The first thing I notice here is that you’re relying on the text property of the text button to determine whether the music is playing or not.

I would advise against using this and rather use the IsPlaying variable on the music object to control whether the music should be on or off, so your code would looks something like this:

local music = game.SoundService.music

music:Play() --// I'm just using the :Play() function to start the music when the player joins the game 
             --//but this isn't strictly necessary 

script.Parent.MouseButton1Click:Connect(function()
    if music.IsPlaying == true then
	    script.Parent.Text = "OFF"
	    music.Playing = false
    else
	    script.Parent.Text = "ON"
	    music.Playing = true
    end
end)

Using the IsPlaying variable makes it so regardless if what text is currently in the TextButton it will still function as intended

1 Like
if music.IsPlaying == true then
    script.Parent.Text = "OFF"
else
    script.Parent.Text = "ON"
end
music.Playing = not music.Playing

this is probably better

2 Likes

You can also use this I guess, I agree it would probably be better.