I am trying to make a command bar and I am trying to make it disappear when I press a certain key code I used:
game:service'UserInputService'.InputBegan:connect(function(inputObject, gameProcessedEvent) if (inputObject.KeyCode == Enum.KeyCode.E) then game.StarterGui.ScreenGui.Input.Visible = true print("Test") end; end);
Also it's a local script in Replicated First
The issue here is that you're changing the Gui object in StarterGui
. Once the character loads, contents of StarterGui
are cloned into the respective player's PlayerGui
folder. Therefore, we need to access the Gui from there. Additionally, :connect()
and :service()
are deprecated. Use :Connect()
and :GetService()
, respectively.
local UIS = game:GetService("UserInputService") local Players = game:GetService("Players") local player = Players.LocalPlayer UIS.InputBegan:Connect(function(key,gameProc) if not gameProc then if key.KeyCode == Enum.KeyCode.E then local gui = player.PlayerGui:FindFirstChild("ScreenGui") if gui then gui.Input.Visible = true end end end end)