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

How can I close my store gui by pressing the X key?

Asked by 3 years ago

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

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

0
Thanks it works. Is there a way I can change it so that if you close the gui and step on the part again you can reopen the gui without resetting your character? thanks jmarsh33 7 — 3y
Ad

Answer this question