I have a store gui that opens by stepping on a part, and I want to make it so that when I press the X key on a keyboard it goes away. This is my script
local UserInputService = game:GetService("UserInputService") local function onInputBegan(input, gameProcessed) if keyCode.keyCode == Enum.KeyCode.X then plr:WaitForChild("PlayerGui").Store.ar.Visible = false end
You need to connect the function you've made to the InputBegan event of UserInputService, you forgot to define "plr" and you've taken input as the argument but you wrote "keycode". Here is your fixed script:
local UserInputService = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local function onInputBegan(input, gameProcessed) if input.KeyCode == Enum.KeyCode.X and not gameProcessed then -- added a check for gameprocessed incase they were writing in chat plr:WaitForChild("PlayerGui").Store.ar.Visible = false end end UserInputService.InputBegan:Connect(onInputBegan)
Hope this fixed your script!