Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

UserInputService, need urgento helpo~?

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

✓ Accepted answer
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

3 comments

0

Thanks!!

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.