Last active
October 5, 2021 23:49
-
-
Save lucasmz-dev/57da4fb94b72d37b60f2e98eff3553d1 to your computer and use it in GitHub Desktop.
BackpackUtil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local StarterGui = game:GetService("StarterGui") | |
| local BackpackUtil = {} | |
| local IsBackpackHidden = false | |
| local HiddenCounter = 0 | |
| local function ChangeBackpackVisibility( | |
| isHidden: boolean | |
| ) | |
| while true do | |
| local success = pcall( | |
| StarterGui.SetCoreGuiEnabled, | |
| StarterGui, | |
| Enum.CoreGuiType.Backpack, | |
| isHidden | |
| ) | |
| if success then | |
| return | |
| end | |
| task.wait() | |
| if isHidden | |
| and HiddenCounter == 0 | |
| or HiddenCounter > 0 | |
| then | |
| return | |
| end | |
| end | |
| end | |
| function BackpackUtil:Hide() | |
| HiddenCounter += 1 | |
| if IsBackpackHidden == false then | |
| IsBackpackHidden = true | |
| task.spawn(ChangeBackpackVisibility, true) | |
| end | |
| end | |
| function BackpackUtil:Show() | |
| if HiddenCounter == 0 then | |
| return | |
| end | |
| HiddenCounter -= 1 | |
| if HiddenCounter == 0 and IsBackpackHidden then | |
| IsBackpackHidden = false | |
| task.spawn(ChangeBackpackVisibility, false) | |
| end | |
| end | |
| return BackpackUtil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment