Issue with debounce

Hey there!
So what I am trying to achieve is, you click a button, the border goes red, youc click that same button again, the border goes green.

If tried looking for tutorials, something about debounce = true, but when I tried it, all it did was go red but then when I clicked it again, nothing happened.

Code
local function mClick()
	
	local debounce = false
	
	if debounce == false then
		SoundS.Sound.Playing = false
		Music.BorderColor3 = Color3.fromRGB(239, 155, 156)
		
	elseif debounce == true then
		
			SoundS.Sound.Playing = true
			Music.BorderColor3 = Color3.fromRGB(184, 239, 160)

			
		end
	end

Music.MouseButton1Click:Connect(mClick)

Thank you for the help! :slight_smile:

When you create an if check you need to adjust the debounce for the other part to work.

E.g

if debounce == false then
debounce = true
-- gui red
else
debounce = false
-- gui blue
end

You need to define the debounce above the function scope.

local debounce = false

local function mClick()
	debounce = not debounce

	if not debounce then
		SoundS.Sound.Playing = false
		Music.BorderColor3 = Color3.fromRGB(239, 155, 156)
	elseif debounce then
		SoundS.Sound.Playing = true
		Music.BorderColor3 = Color3.fromRGB(184, 239, 160)
	end
end

Music.MouseButton1Click:Connect(mClick)

You also need to set the debounce as true, then when you lick it again it turns false.