How do I completely disable a player’s inventory? (Like when you press the keybind the inventory UI won’t show up)
It works in a similar way since you’re disabling a part of the CoreGui, but it’s not through SetCore
– instead, it uses SetCoreGuiEnabled
:
-- LocalScript Code
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
Resources
List of CoreGui types - Creator Documentation
SetCoreGuiEnabled
- Creator Documentation
Post Edits Changelog
Edit #1 (May 20th, 2022) – Updated the Roblox Developer Hub Documentation links throughout this post to the new Creator Documentation pages.
Because the Roblox Developer Hub will be superseded by Roblox’s Creator Documentation, I figured that it would be better to replace the links in this post sooner rather than later so that the main post wouldn’t have broken links in the far future.
Before
CoreGuiType
- Developer Hub Documentation
SetCoreGuiEnabled
- Developer Hub Documentation
After
CoreGuiType
- Creator Documentation
SetCoreGuiEnabled
- Creator Documentation
but how do I enable it after?
//////////////////
im not that type of guy who say “git gud” but damn, LUA is one of the most readable languages, and with the roblox studio API is even easier, how do you manage to do this question? have you even tried to read HALF of the code?
To enable it afterwards, you would write the same thing somewhere else in a LocalScript
, except you’d replace false
with true
to indicate that it should be enabled.
However, you’d want to make sure that the code is contained within something such as a function to ensure it only runs when you want it to. Otherwise, if it’s placed directly into a LocalScript
like the original example was, the Backpack would be immediately turned off at the top of the script and then quickly turned back on when it reaches the section of code where it was re-enabled.
For example, if you wanted to re-enable it only after the player touched a Part in the Workspace, here’s how you could achieve that:
Example #1
-- LocalScript Code
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local examplePart = workspace:WaitForChild("examplePart")
local function activateToReEnableBackpack()
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end
examplePart.Touched:Connect(function(otherPart)
local model = otherPart:FindFirstAncestorOfClass("Model")
if not model then return end
local playerCheck = Players:GetPlayerFromCharacter(model)
if not playerCheck then return end
if playerCheck == LocalPlayer then
activateToReEnableBackpack()
end
end)
However, if you wanted something where players could toggle this on and off manually at any time, such as allowing them to press a TextButton
to turn it on or off, you would instead need to set it to the opposite of the current value.
This could be achieved by checking what it’s currently set to with StarterGui:GetCoreGuiEnabled()
and then calling StarterGui:SetCoreGuiEnabled()
with the opposite value:
Example #2
-- LocalScript Code
local StarterGui = game:GetService("StarterGui")
local TextButton = script.Parent
TextButton.Activated:Connect(function()
local currentValue = StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.Backpack)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, not currentValue)
end)