Sound mute problem help to fix

hello, I’m creating a muta button, but I have a problem, I have 2 music and I made a script so that they randomly turn on and I wanted to make muta strings for them, but it doesn’t work, I torment them the sound doesn’t work and when I turn them on, they don’t work my script

local Go = game.Workspace.MusicScript.Go
local play = false

script.Parent.MouseButton1Click:Connect(function()
	if play then
		GoodSound.Volume = 1     --volume from the music when it's on
		Go.Volume = 1
		play = false
		script.Parent.Round.ImageColor3 = Color3.fromRGB(234,0,0)
		script.Parent.Text = "Off"
		GoodSound.Volume = 0 
	    Go.Volume = 0 else 
		play = true        
		script.Parent.Round.ImageColor3 = Color3.fromRGB(0,255,0)
    	script.Parent.Text = "On"
	end
end)

Are you guys serious you can’t help?

how to fix the problem please help

I reformatted the code ever so slightly, and the problem is quite clear now!

You havee the GoodSound.Volume = 0 and Go.Volume = 0 thing BEFORE else, when I believe you want them AFTER the else

Your code (reformatted):

local Go = game.Workspace.MusicScript.Go
local play = false

script.Parent.MouseButton1Click:Connect(function()
	if play then
		GoodSound.Volume = 1     --volume from the music when it's on
		Go.Volume = 1
		play = false
		script.Parent.Round.ImageColor3 = Color3.fromRGB(234,0,0)
		script.Parent.Text = "Off"
		GoodSound.Volume = 0 
	    Go.Volume = 0 
    else 
		play = true        
		script.Parent.Round.ImageColor3 = Color3.fromRGB(0,255,0)
    	script.Parent.Text = "On"
	end
end)

Corrected code:

local Go = game.Workspace.MusicScript.Go
local play = false

script.Parent.MouseButton1Click:Connect(function()
	if play then
		GoodSound.Volume = 1     --volume from the music when it's on
		Go.Volume = 1
		play = false
		script.Parent.Round.ImageColor3 = Color3.fromRGB(234,0,0)
		script.Parent.Text = "Off"
    else 
        GoodSound.Volume = 0 
	    Go.Volume = 0 
		play = true        
		script.Parent.Round.ImageColor3 = Color3.fromRGB(0,255,0)
    	script.Parent.Text = "On"
	end
end)

Screenshot_2

at the time of this script I was fixing it I have 2 music right now

You assigned the variable GoodSound previously I asssume? Don’t delete that part of the code when pasting the correction in, only replacing the relevant code.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.