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

UserInputService, need urgento helpo~?

Asked by 8 years ago
local player = game.Players.LocalPlayer
local inventoryVis = player.PlayerGui.Inventory.Visible

UIS = game:GetService("UserInputService")

UIS.InputBegan(function(input, process)
    if not process then
        if input.KeyCode == Enum.KeyCode.G and inventoryVis == false then
            --fetch inventory
            inventoryVis = true
        elseif input.KeyCode == Enum.KeyCode.G and inventoryVis == true then
            --close inventory
            inventoryVis = false
        end
    end
end)

Trying to get it so that whenever the player presses G, an inventory GUI becomes visible, and turns it off if its already visible.

1 answer

Log in to vote
1
Answered by
Hero_ic 502 Moderation Voter
8 years ago
local player = game.Players.LocalPlayer
local inventoryVis = player.PlayerGui.Inventory.Visible

UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input, process)
    if not process then
        if input.KeyCode == Enum.KeyCode.G and inventoryVis == false then
            --fetch inventory
            inventoryVis = true
        else then
            --close inventory
            inventoryVis = false
        end
    end
end)

this should fix it all I did was remove the input.KeyCode == Enum.KeyCode.G and inventoryVis == true also you where missing "connect"

hope this helped. ~KIHeros

0
Thanks!! konichiwah1337 233 — 8y
0
@KiHeros 1) You shouldn't use variables to get properties, like you did with 'inventoryVis'. You will store the value and not the key (property) to it. So, if 'Inventory'-s Visible property does change, the variable will not. You should just store the 'Inventory' object itself. 2) At line 11, you wrote 'else then' which will error. LetThereBeCode 360 — 8y
0
PS. I know you have helped @konichiwah1337 further, but you should've updated the code, so other people can get help if they stumble upon similar problem. LetThereBeCode 360 — 8y
Ad

Answer this question