GUI opening error

My problem is that when I turn on the frame visibility option for the second time, it doesn’t work, and it doesn’t work when I turn off the GUI via the close button. I can provide all the code

Frame open script:

local script_parent = script.Parent
local gui = script.Parent.Parent.Parent:FindFirstChild("TeamFrame")
local frame = script.Parent.Parent.Parent:FindFirstChild("SecFrame")

function Click()
	local play = script_parent:FindFirstChild("UI_ButtonClick"):Play()
	wait(0.136)
end

function Sound()
	local play = script_parent:FindFirstChild("ui_hover_ugd"):Play()
	wait(0.5)
end

function invise()
	frame.Visible = true
	gui.Position = UDim2.new(0.228, 0, 0.2, 0) + UDim2.new(0, 0, -0.9, 0)
	Click()
end

local textButton = script_parent:FindFirstChild("TextButton")
textButton.MouseEnter:Connect(Sound)

textButton.MouseButton1Click:Connect(function()
	if frame.Visible == false then
		invise()
		print("One")
	else
		frame.Visible = false
		frame.Position = UDim2.new(0.228, 0, 0.2, 0)
		gui.Position = UDim2.new(0.228, 0, 0.2, 0) + UDim2.new(0, 0, -0.9, 0)
		print("Two")
	end
end)

Close button script:

script.Parent.MouseButton1Click:Connect(function()
	local parent = script.Parent.Parent
	parent:TweenPosition(UDim2.new(0.228, 0, -0.8, 0), "Out", 0.5)
	wait(1)
	parent.Visible = false
end)

open gui script:

local gui = script.Parent.Parent.Parent:FindFirstChild("TeamFrame")

script.Parent.MouseButton1Click:Connect(function()
	local frameList = {
		"MedicFrame",
		"CofFrame",
		"AdminFrame",
		"SecFrame",
		"EmegSecFrame",
		"ReserhFrame"
	}

	local shouldShowGui = true

	for _, frameName in ipairs(frameList) do
		local frame = script.Parent.Parent.Parent:FindFirstChild(frameName)
		if frame and frame.Visible == true then
			shouldShowGui = false
			break
		end
	end

	if shouldShowGui then
		gui.Visible = true
		gui:TweenPosition(UDim2.new(0.228, 0, 0.2, 0), "Out", 1)
	end
end)
1 Like

Are you able to provide the error? If one is present, it’ll help with identifying the issue.

It doesn’t give any errors, working else when i pressed the button second attempt

So like you pressed it once and nothing, but the second attempt of pressing it interacts correctly?

No, for the first time everything is fine and the first condition is triggered, but the second time when the second condition is triggered, else when team frame just changed position

Are you able to provide a small video showcasing the issue? Might help me figure out the exact issue.

If it’s relating to conditional statements, I’d recommend changing:
if frame.Visible == false to if not frame.Visible
It’s genuinely good practice, furthermore is there a video?

Okay so let me see if I’m seeing it correctly, been a long day.

So you start on the first page, you click on an element which takes you too the second page, once you close that second page and try to reopen it with the open button it doesn’t want to open? Not sure if that’s the exact issue or I’m just seeing things.

Yes, the second time does not want to go to the second page

local script_parent = script.Parent
local gui = script.Parent.Parent.Parent:FindFirstChild("TeamFrame")
local frame = script.Parent.Parent.Parent:FindFirstChild("SecFrame")

function Click()
	local play = script_parent:FindFirstChild("UI_ButtonClick"):Play()
	wait(0.136)
end

function Sound()
	local play = script_parent:FindFirstChild("ui_hover_ugd"):Play()
	wait(0.5)
end

function invise()
	frame.Visible = true
	gui.Position = UDim2.new(0.228, 0, 0.2, 0) + UDim2.new(0, 0, -0.9, 0)
	Click()
end

local textButton = script_parent:FindFirstChild("TextButton")
textButton.MouseEnter:Connect(Sound)

textButton.MouseButton1Click:Connect(function()
	if not frame.Visible then
		invise()
		print("One")
	else
		frame.Visible = false
		frame.Position = UDim2.new(0.228, 0, 0.2, 0)
		gui.Position = UDim2.new(0.228, 0, 0.2, 0) + UDim2.new(0, 0, -0.9, 0)
		print("Two")
	end
end)

Close Button

script.Parent.MouseButton1Click:Connect(function()
	local parent = script.Parent.Parent
	parent:TweenPosition(UDim2.new(0.228, 0, -0.8, 0), "Out", 0.5)
	wait(0.5) -- match the wait time here to match the tween time or tweenCompleted:Wait()
	parent.Visible = false
end)

GUI Open

local gui = script.Parent.Parent.Parent:FindFirstChild("TeamFrame")

script.Parent.MouseButton1Click:Connect(function()
	local frameList = {
		"MedicFrame",
		"CofFrame",
		"AdminFrame",
		"SecFrame",
		"EmegSecFrame",
		"ReserhFrame"
	}

	local shouldShowGui = true

	for _, frameName in ipairs(frameList) do
		local frame = script.Parent.Parent.Parent:FindFirstChild(frameName)
		if frame and frame.Visible then
			-- frame.Visible = false -- Unsure if you want to try this out
			gui.Position = UDim2.new(0.228, 0, 0.2, 0) + UDim2.new(0, 0, -0.9, 0)
			shouldShowGui = false
			break
		end
	end

	if shouldShowGui then
		gui.Visible = true
		gui:TweenPosition(UDim2.new(0.228, 0, 0.2, 0), "Out", 1)
	end
end)

This is just a review of your code, minor changes were set.
I’ve corrected the conditional statement if frame.Visible == false,
and I’ve matched the wait time to match the tween time.

In the GUI Open, I’ve added a line for frame.Visible = false, unsure if you want to add that however that may/not be the cause as I don’t have your exact structure replica and this being an overview.

If this doesn’t work, and you need further help, feel free to shoot me a PM with the model.

Thank you so much I will read this code and make the necessary adjustments and test

1 Like