Im trying to make the tabs switch color when i click on one but when i play the game and click the tab it works but then when i click back it doesnt Help pls Local Script:

local player = game.Players.LocalPlayer

local SB = script.Parent --Dad Frame

local SF = script.Parent.SettingsFrame
local KBF = script.Parent.KeyBindsFrame
local KBT = script.Parent.KeyBindsTab
local ST = script.Parent.SettingsTab
local SettingsOpen = false
local KeybindsOpen = false

SB.MouseButton1Click:Connect(function()
	KBF.Visible = false
	KBT.Visible = true
	ST.Visible = true
	SF.Visible = true
	SettingsOpen = true
	--When Settings button is clicked these frames will pop up
	
	
	if SettingsOpen == true then
		KBT.MouseButton1Click:Connect(function()
			SF.Visible = false
			SettingsOpen = false
			KeybindsOpen = true
			KBF.Visible = true
			--Sets the rest of the Settings visibility to false
			KBT.TextColor3 = ST.TextColor3
			KBT.BorderColor3 = ST.BorderColor3
			--sets the new colors for design :D
			ST.TextColor3 = Color3.new(0.305882, 0.305882, 0.305882)
			ST.BorderColor3 = Color3.new(0.305882, 0.305882, 0.305882)
			--Sets color for Settings tab design :D
		end)
	else
		ST.MouseButton1Click:Connect(function()
			SF.Visible = true
			SettingsOpen = true
			KeybindsOpen = false
			KBF.Visible = false
			--Sets the rest of the Settings visibility to false
			ST.TextColor3 = KBT.TextColor3
			ST.BorderColor3 = KBT.BorderColor3
			--sets the new colors for design :D
			KBT.TextColor3 = Color3.new(0.305882, 0.305882, 0.305882)
			KBT.BorderColor3 = Color3.new(0.305882, 0.305882, 0.305882)
			--Sets color for Settings tab design :D
			end)
		end
	end)