Gui Still Visible When Visible Is Set to False

I have been working on the inventory GUI for my game and wanted to tween it so it opens smoothly. Tweening the inventory open and closed works fine, except when the inventory is closed, it is still there as a really small line.

Here is a video:

In the video, I open the inventory, where it tweens open just fine, but when I close it, the tween works, but there is a line in the centre of the screen.

Code for opening the inventory:

local openButton = script.Parent
local inGameGui = openButton.Parent.Parent
local frame = inGameGui.Inventory

openButton.Activated:Connect(function()
	for i, v in pairs(inGameGui:GetChildren()) do --Hide all gui objects that are not this frame.
		if v ~= frame then
			v.Visible = false
		end
	end
	
	frame.Visible = true
	frame:TweenSize(
		UDim2.new(1.6, 0, 0.8, 0),
		"In",
		"Linear",
		0.1
	)
end)

Code for closing the inventory:

local closeButton = script.Parent
local frame = closeButton.Parent
local inGameGui = frame.Parent

closeButton.Activated:Connect(function()	
	frame:TweenSize(
		UDim2.new(0, 0, 0.8, 0),
		"In",
		"Linear",
		0.1
	)
	wait(0.1)
	frame.Visible = false	

	for i, v in pairs(inGameGui:GetChildren()) do --Show all gui objects that are not this frame.
		if v ~= frame then
			v.Visible = true
		end
	end
end)

I have checked that visible is set to false after the inventory is tweened closed, so I am unsure of why the inventory is still present when it should be scaled to 0 on the X axis and invisible.

If you have any suggestions, please leave a reply!

1 Like

Hi, test this. Add more time in wait and show first and then hide the frame.

local closeButton = script.Parent
local frame = closeButton.Parent
local inGameGui = frame.Parent

closeButton.Activated:Connect(function()	
	frame:TweenSize(
		UDim2.new(0, 0, 0.8, 0),
		"In",
		"Linear",
		0.1
	)
	wait(0.2)
	for i, v in pairs(inGameGui:GetChildren()) do --Show all gui objects that are not this frame.
		if v ~= frame then
			v.Visible = true
		end
	end

	frame.Visible = false	
end)
1 Like

I have tried that out, and the problem still persists. I have tried waiting for 1 second too with no luck. I have set visible to false after the loop and printed out the value of frame.visible, and it says false, but as you know the GUI is still visible.

If you have any more ideas, please do not hesitate to share them!

I try…, but can`t reproduce de bug.

local inGameGui = script.Parent.ScreenGui
local openButton =inGameGui.Open 
local frame = inGameGui.Frame
local closeButton = frame.TextButton

openButton.Activated:Connect(function()
	for i, v in pairs(inGameGui:GetChildren()) do --Hide all gui objects that are not this frame.
		if v ~= frame then
			v.Visible = false
		end
	end
	
	frame.Visible = true
	frame:TweenSize(
		UDim2.new(0, 500, 0, 500),
		"In",
		"Linear",
		0.1
	)
end)

closeButton.Activated:Connect(function()	
	frame:TweenSize(
		UDim2.new(0, 0, 0, 0),
		"In",
		"Linear",
		0.1
	)
	wait(0.1)
	frame.Visible = false	
	
	for i, v in pairs(inGameGui:GetChildren()) do --Show all gui objects that are not this frame.
		if v ~= frame then
			v.Visible = true
		end
	end
end)

I have tried to see if I could replicate the issue in another game, and also found I could not replicate the issue.

I am going to see if I can tweak some things in the inventory GUI, hopefully fixing the problem.

After testing some things out, I have noticed that the frame is going invisible, but its children are not. I am not sure why they do not go invisible as they should when their parent’s visible property gets set to false, but I was still able to work around this.

I looped through each child of the inventory and set their visible property to true and false depending on if the inventory was opening or closing.

Thanks for the help @fstnando77!

I’m glad you found it able to solve it. Best regards. :wave: