So I want to open an Inventory when I press a button. I made a script but it just won't work and I can't figure it out. Can some1 help me? I'm prety new at scripting so maybe it's prety obvius what I should do.

local inv = game.StarterGui.InventoryGui
local ContextActionService = game:GetService("ContextActionService")
inv.Enabled = false

local function openInv(actionName, inputState, inputObject)
	if actionName == "OpenInv" then
		if inputState == Enum.UserInputState.Begin and inv.Enabled == false then
			inv.Enabled = true
		elseif inputState == Enum.UserInputState.Begin and inv.Enabled == true then
			inv.Enabled = false
		end
	end
end


ContextActionService:BindAction("OpenInv", openInv, true, Enum.KeyCode.G)

(ps. Sorry for my English if it's a little bad.)

3 comments

0

Click "view source" to see how it really looks. Some lines shifted.

0

Is it a local script or normal script? If its a normal script it has to be a Local Script. If it is a local script make sure it is in either A Player’s PlayerGui A Player’s PlayerScripts. or The ReplicatedFirst service

0

Thx, Nervousmrmonkey2. It works now. I also had to change "local inv = game.StarterGui.InventoryGui" to "local inv = game.Players.LocalPlayer.PlayerGui:WaitForChild("InventoryGui")".