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

using one script would work and it could be simple

something like this

local TS = game:GetService("TweenService")
local tInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local Main = script.Parent
local Inventory = Main.InventoryFrame
local Open = Main.InventoryButtonFrame.InventoryButton
local Exit = Inventory.ExitButton

-- Try using a global value instead of a BoolValue object
is_tweening = false -- To avoid spamming tweens (spamming open/close)

local function TweenInventory(Open)
  if is_tweening then return end -- If the inventory is being closed/opened then ignore 
  is_tweening = true
	
  local Tween -- Instead of looping you could also use a CanvasGroup and tween the GroupTransparency
  for _, Item in Inventory:GetChildren() do
    local Properties = {}
    local ShowOrHide = Open and 0 or 1
    if Item:IsA("ScrollingFrame") then Item.Visible = Open continue end
    if Item:IsA("TextButton") then Properties = {["BackgroundTransparency"] = ShowOrHide, ["TextTransparency"] = ShowOrHide} end
    if Item:IsA("ImageLabel") then Properties = {["ImageTransparency"] = ShowOrHide} end
    Tween = TS:Create(Item, tInfo, Properties)
    Tween:Play()
  end 
	
  Tween.Completed:Connect(function()
    Inventory.Visible = false
    is_tweening = false
  end)
end

local function OpenInventory()
  if Inventory.Visible then return end -- If the inventory is already open then ignore the click
  TweenInventory(true)
end

local function CloseInventory()
  if not Inventory.Visible then return end -- If the inventory is already closed then ignore the click
  TweenInventory(false)
end

Exit.MouseButton1Click:Connect(CloseInventory)
Open.MouseButton1Click:Connect(OpenInventory)
1 Like

We tried out this script and noticed that it instantly opened then closed the inventory. Tried changing the script so the inventory wouldn’t close immediately, which then caused all windows to open at once and would make the exit invisible and not possible to press. We then figured out that this script also ends up having the same issue as we already have when it comes to actually closing the inventory. So it technically brings us back to the same core problem, which is the first click not being able to be recognized as a click on the exit button upon the inventory being the first UI opened after joining the game.

Thank you, it was a very much so worth attempting.

you put the script under main and disabled the other two inventory scripts right?

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