Elseif won't work?!

the elseif doesn’t work as intended, anyone know why?
i want it to close the gui after clicked while the gui is open

local Clickable = true

Preview = script.Parent.Parent:WaitForChild("Preview")
for i, Frame in pairs(script.Parent:GetChildren()) do
	if Frame:IsA("Frame") then
		Frame:WaitForChild("Button").MouseButton1Click:connect(function()
			if Frame.Name == "Settings" and Clickable == true and script.Parent.Parent.Parent.Menus.Settings.Visible == false then
				Clickable = false
				local Settings = script.Parent.Parent.Parent.Menus:WaitForChild("Settings")
				Settings.Position = UDim2.new(0.5, 0,0.65, 0)
				Settings.Exit.Transparency = 1
				Settings.Visible = true			
				Settings:TweenPosition(UDim2.new(0.5, 0,0.5, 0))
				for i, Frame in pairs(Settings.Main.ScrollingFrame:GetChildren()) do
					if Frame:IsA("Frame") then
						Frame.Visible = true
						Frame.Size = UDim2.new(0.609, -10,-0.023, 50)
						Frame:TweenSize(UDim2.new(1, -10,0.023, 50))
						wait(0.075)
						end
				end
				repeat
					wait(0.01)
					game.Lighting.Blur.Size = game.Lighting.Blur.Size+1
				until game.Lighting.Blur.Size == 10
				repeat
					wait()
					Settings.Exit.Transparency = Settings.Exit.Transparency-0.05
				until Settings.Exit.Transparency == 0
				Clickable = true
			elseif Frame.Name == "Settings" and Clickable == true then
				Clickable = false
				local Settings = script.Parent.Parent.Parent.Menus:WaitForChild("Settings")
				Settings.Visible = false
				Settings.Exit.Transparency = 0
				repeat
					wait(0.01)
					game.Lighting.Blur.Size = game.Lighting.Blur.Size-1
				until game.Lighting.Blur.Size == 0		
				for i, Frame in pairs(Settings.Main.ScrollingFrame:GetChildren()) do
					if Frame:IsA("Frame") then
						Frame.Visible = false
						Clickable = true
					end
				end
			end
		end)
	end
end

Tried to clean up your code, it may be working now:

local TS = game:GetService("TweenService")

local function yieldingTween(object: Instance, t: number, goal: {[string]: any})
	local tween = TS:Create(object, TweenInfo.new(t), goal)
	tween:Play()
	tween.Completed:Wait()
end

local function changeVisibility(set: Instance)
	local sf = set:WaitForChild("Main"):WaitForChild("ScrollingFrame")
	for _, frame in pairs(sf:GetChildren()) do
		if not frame:IsA("Frame") then continue end
		frame.Visible = set.Visible
		if not set.Visible then continue end
		frame.Size = UDim2.new(0.609, -10, -0.023, 50)
		frame:TweenSize(UDim2.new(1, -10, 0.023, 50))
		task.wait(0.075)
	end
end

local debounce = false
for _, frame in pairs(script.Parent:GetChildren()) do
	if not frame:IsA("Frame") then continue end
	frame:WaitForChild("Button").MouseButton1Click:Connect(function()
		if debounce then return end
		debounce = true
		local Settings = script.Parent.Parent.Parent.Menus:WaitForChild("Settings")
		Settings.Visible = not Settings.Visible
		Settings.Exit.Transparency = Settings.Visible and 1 or 0
		if frame.Name == "Settings" and Settings.Visible then
			Settings.Position = UDim2.fromScale(0.5, 0.65)
			Settings:TweenPosition(UDim2.fromScale(0.5, 0.5))
			changeVisibility(Settings)
			yieldingTween(game.Lighting.Blur, 0.1, {Size = 10})
			yieldingTween(Settings.Exit, 0.27, {Transparency = 0})
		elseif frame.Name == "Settings" then
			yieldingTween(game.Lighting.Blur, 0.1, {Size = 0})
			changeVisibility(Settings)
		end
		debounce = false
	end)
end

Tell me if any errors occur.

Hi nyrion, could u help me with another issue with this code, i want have it so you can open multiple menus not just the ‘settings’ one, ive tried implement this myself but it unfortunately didnt work

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