Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the InventoryFrame NOT disapear?

I can see in the debugger that the InventoryFrame is set to false, but nothing happens. InventoryFrame is a frame consisting of other frames. I will remember to accept a fulfilling answer

InventoryFrame = game.StarterGui.ToolBar.DisplayInventory.InventoryFrame
script.Parent.Activated:Connect(function()
	if InventoryFrame.Visible == false then
		InventoryFrame.Visible = true
	else
		InventoryFrame.Visible = false
	end
end)

2 answers

✓ Accepted answer

Simple fix! Make sure you're using a localscript. You can't use the StarterGui.

local Players = game:GetService("Players")
local PlayerGui = Players.LocalPlayer.PlayerGui
InventoryFrame = PlayerGui.ToolBar.DisplayInventory.InventoryFrame
script.Parent.Activated:Connect(function()
    if InventoryFrame.Visible == false then
        InventoryFrame.Visible = true
    else
        InventoryFrame.Visible = false
    end
end)

5 comments

1

InventoryFrame.Visible = not InventoryFrame.Visible is how you toggle a bool

2

Yes but there are other ways to do it smh ^

0

Yes, and ideally, a programmer should know all of them, and their relative merits. Toggle-by-assignment is a micro-optimization that won't matter one bit in this code, I only added the comment because it's something useful to know if you find yourself having to toggle a bool in a performance-critical nested loop.

1

Emily, nobody cares. The most annoying thing is when people criticize code for the wrong reasons lol, the logic works. And its not even that jank. 

0

What even is the point of using = not? Half the time it doesn't even work, just use if enter bool here.Value/Visible = false/true.

Simple version of the if statement (4 lines):

InventoryFrame = game.StarterGui.ToolBar.DisplayInventory.InventoryFrame
script.Parent.Activated:Connect(function()
   InventoryFrame.Visible = not InventoryFrame.Visible
end)

4 comments

0

still didn't solve problem though

0

yeah but we dont even know if he identified it right

0

cant you also just do InventoryFrame.Visible = false?

0

did you just not get the word "simple"?

This discussion is preserved as it was. New answers, comments, and votes are closed.