This gui closing script isnt working properly and I dont know why

For some reason this script doesn’t work on its own unless another gui is closed first.
So if I open this gui first and try to close it, it doesn’t detect the player clicking the exit button

but if I open another gui and close it before trying to close this one it will finally work perfectly fine as if nothing was wrong.

Me and my friends revised this hundreds of times and still cannot figure out what the issue is. We see no issues…

all my other scripts have basically the same closing script and they all work fine… its just this one causing issues.

SCRIPT:

local ExitButton = script.Parent
local OpenedInventory = script.Parent.Parent

local Titles = OpenedInventory.TitlesButton
local Bakcground = OpenedInventory.InventoryBackground

local HatsFrame = OpenedInventory.HatsFrame
local TitlesFrame = OpenedInventory.TitlesFrame
local PetsFrame = OpenedInventory.PetsFrame
local ColorsFrame = OpenedInventory.ColorsFrame

local Open = OpenedInventory.OpenClose

local Tweening = game:GetService("TweenService")

function leftClick()
	
	if Open.Value == true then
		
		Open.Value = false

		local Tween = Tweening:Create(Bakcground, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 1}):Play()
		local Tween = Tweening:Create(Titles, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		local Tween = Tweening:Create(Titles, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(ExitButton, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 1}):Play()
		local Tween = Tweening:Create(HatsFrame, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Visible = false}):Play()
		local Tween = Tweening:Create(TitlesFrame, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Visible = false}):Play()
		local Tween = Tweening:Create(PetsFrame, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Visible = false}):Play()
		local Tween = Tweening:Create(ColorsFrame, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Visible = false}):Play()
		wait(1)
		OpenedInventory.Visible = false
	end

end

script.Parent.MouseButton1Click:Connect(leftClick)

Here is a video showing me trying to click close and it not working but then magically fixing itself after I open anything else.

8 Likes

Looks like you have local ExitButton = script.Parent defined, but I’m not seeing it referenced later in the script.

ExitButton.MouseButton1Click:Connect(leftClick)
script.Parent.MouseButton1Click:Connect(leftClick)
1 Like

The issue could be with the open script, but I’m not sure. (also just want to point out that you spelled the variable background wrong lol)

2 Likes

yeah it is spelled wrong but I still used the typo for all of the rest of the script so it still works.

1 Like

Its just there for the tween but script.parent is still used

1 Like

Again, I believe the issue is within the opening script, so could you show us that?

2 Likes
local InventoryButton = script.Parent
local OpenedInventory = script.Parent.Parent.Parent:FindFirstChild("InventoryFrame")

local Exit = OpenedInventory.ExitButton
local Titles = OpenedInventory.TitlesButton
local Bakcground = OpenedInventory.InventoryBackground

local HatsFrame = OpenedInventory.HatsFrame
local Bow = HatsFrame.BowHatButton
local Cheese = HatsFrame.CheeseHatButton
local Mono = HatsFrame.MonocleHatButton
local Ring = HatsFrame.RingsHatButton
local Top = HatsFrame.TopHatButton

local Open = OpenedInventory.OpenClose

local Tweening = game:GetService("TweenService")

local OpenedShop = script.Parent.Parent.Parent:FindFirstChild("ShopFrame")
local ShopClose = OpenedShop.OpenClose

local Ratty = OpenedShop.Ratty
local RatSpeak = OpenedShop.RatSpeak
local ShopBackground = OpenedShop.ShopBackground
local ShopTitles = OpenedShop.TitlesButton
local ShopPets = OpenedShop.PetsButton
local ShopHats = OpenedShop.HatsButton
local ShopColors = OpenedShop.ColorsButton
local ShopExit = OpenedShop.ExitButton

function leftClick()
	
	if Open.Value == true then return end
	
	if ShopClose.Value == true then

		ShopClose.Value = false

		local Tween = Tweening:Create(Ratty, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(RatSpeak, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		local Tween = Tweening:Create(RatSpeak, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopBackground, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopTitles, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopTitles, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopPets, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopPets, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopHats, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopHats, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopColors, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopColors, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		local Tween = Tweening:Create(ShopExit, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 1}):Play()
		
		wait(0.5)
		
		OpenedShop.ColorsFrame.Visible = false
		OpenedShop.HatsFrame.Visible = false
		OpenedShop.PetsFrame.Visible = false
		OpenedShop.TitlesFrame.Visible = false
		OpenedShop.BuyFrame.Visible = false
		OpenedShop.Visible = false

	end
	
	if Open.Value == false then
		
		Open.Value = true
		OpenedInventory.Visible = true

		local Tween = Tweening:Create(Bakcground, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 0}):Play()
		local Tween = Tweening:Create(Titles, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
		local Tween = Tweening:Create(Titles, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 0}):Play()
		local Tween = Tweening:Create(Exit, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {ImageTransparency = 0}):Play()
		local Tween = Tweening:Create(HatsFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Visible = true}):Play()
	end
	
end

script.Parent.MouseButton1Click:Connect(leftClick)
1 Like

Why are you tweening visible = false?

1 Like

Also what’s script.Parent in this script

1 Like

My friend is the scripter and he just preferred doing it that way.

1 Like

That’s the exit button its referring too

2 Likes

You can’t tween visible = false just UI.Visible = false

1 Like

Put print statements before and after the return

1 Like

To see if it’s being called correctly or running after the return

1 Like

we changed that just now and it didn’t change anything.

2 Likes

We’ve already put a print statement and the only time it does not work is only when you open and close it first

but if you open and close another gui first it works perfectly fine later…

1 Like

Are you also planning to close it once

1 Like

You are setting the open.Value to true after the first click so if you click it again it won’t run

its an inventory. We want you to be able to open it multiple times.

the first click checks if it is true