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

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

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

✓ Accepted answer

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!

1 comment

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

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