I need to make a settings button

My script is and i get no errors it has to be a toggle button and it opens but not closes

local settingsF = script.Parent.SettingsF

SettingsB.MouseButton1Click:Connect(function()
	local SettingsOpen = false
	
	if SettingsOpen == false then
		settingsF.Visible = true
		SettingsOpen = true
	elseif SettingsOpen == true then
		settingsF.Visible = false
		SettingsOpen = false
	end
end)

Consider placing SettingsOpen outside of the event, otherwise it won’t change from false to true.

local settingsF = script.Parent.SettingsF
local SettingsOpen = false

SettingsB.MouseButton1Click:Connect(function()
	if SettingsOpen == false then
		settingsF.Visible = true
		SettingsOpen = true
	elseif SettingsOpen == true then
		settingsF.Visible = false
		SettingsOpen = false
	end
end)

worked thanks for the help its fixed now

You can reaaally simplify this code by doing

local settingsF = script.Parent.SettingsF

SettingsB.MouseButton1Click:Connect(function()
	
		settingsF.Visible = not settingsF.Visible
	
end)

so if it is true, it will set it to not true (false), if false, will set to not false(true)

2 Likes