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

Activate a GUI by pressing a key?

I need to know how to activate the menu in my game with the m key. Please help.

1 answer

If you mean making a GUI Visible, this should work:

local uis = game:GetService("UserInputService") -- Get the UserInputService.
local ui = script.Parent --Define ScreenGui
local frame = ui.Frame --Define Frame

uis.InputBegan:connect(function(inputObject) -- Function fires when any input from your device is recieved, where inputObject is an Instance with a Child containing information about the key, button or anything else.
	if inputObject.KeyCode == Enum.KeyCode.E then -- If statement that checks if the KeyCode is E
		frame.Visible = true
	end
end)

Read more here: http://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan

2 comments

0

what do i put it in ?

0

A local script. With line 3 edited to be the path of the frame. I urge you to read this, joshmatt1245: http://wiki.roblox.com/?title=Scripting_Book

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