UserInputService and GUI

Can I access GUI elements (text label,imagelabels etc.)with UserInputService(KeyPressing)?

1 Like

Can you explain a little bit more about what you want to achieve?

When the player presses one key appears a GUI and disappears another

Since UIS is only accessible on the client side, you’ll need to use a LocalScript to use it:

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local PlayerGui = Player:WaitForChild("PlayerGui")
local GuiToConfigure = PlayerGui:WaitForChild("YourGuiNameHere")

UIS.InputBegan:Connect(function(Key, Chatted)
    if Chatted then
        return
    end
    
    if Key.KeyCode == Enum.KeyCode.E then
        GuiToConfigure.Enabled = true
    end
end)
1 Like

Then, yes. You can use UserInputService in a LocalScript to do that.

For Example:

UserInputService.InputBegan:Connect(function(input)
      if input.UserInputType == Enum.UserInputType.Keyboard then
         if input.KeyCode == Enum.KeyCode.E -- For example, if a player presses E the frame will be visible.
             Frame.Visible = true
         end
     end
end)
1 Like