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

I want to open an Inventory when I press a button, but it won't work. What I should do?

Asked by 3 years ago

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.)

0
Click "view source" to see how it really looks. Some lines shifted. cossie300 -2 — 3y
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 Nervousmrmonkey2 118 — 3y
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")". cossie300 -2 — 3y

Answer this question