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

KeyDown function to enable GUI?

I'm making a menu GUI in my game, and would like to have them press M for it to open. I've tried a few times and can't grasp it. I'm really new to this and would like some help. Thanks :)

1 answer

For more info about this type of stuff: https://developer.roblox.com/en-us/articles/Keyboard-Input-Methods Using the example from here, this is what I would do (localscript)

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
		game.Players.LocalPlayer.PlayerGui.replacewithgui.Enabled=true
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Hope it helps, if it did be sure to accept the answer!

6 comments

0

Wait so, where do i put the reaction for the GUI to enable?

0

ah, i see the "replacewithgui" my bad. im just blind aha

0

Didnt work, thanks though. ;-;

1

Reason why that didn't work is because he's missing an "s" after game.Player, it's supposed to be game.Players. Also make sure that you put this code in a Local Script inside of the GUI, and change "Enum.KeyCode.R" to "Enum.KeyCode.M" if you want. (just changes what button you press to activate the GUI)

0

if this works im gonna be mad at myself

0

lmao @godlydeath I saw that, fixed the typo.

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