Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

Why does the InventoryFrame NOT disapear?

Asked by 5 years ago

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

Log in to vote
1
Answered by
harstud 218 Moderation Voter
5 years ago

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)
1
InventoryFrame.Visible = not InventoryFrame.Visible is how you toggle a bool EmilyBendsSpace 1025 — 5y
2
Yes but there are other ways to do it smh ^ greatneil80 2647 — 5y
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. EmilyBendsSpace 1025 — 5y
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.  Psudar 882 — 5y
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*. harstud 218 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)
0
still didn't solve problem though bhqpping 80 — 5y
0
yeah but we dont even know if he identified it right speedyfox66 237 — 5y
0
cant you also just do InventoryFrame.Visible = false? Si_SenorTN 25 — 5y
0
did you just not get the word "simple"? speedyfox66 237 — 5y

Answer this question