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

KeyDown function to enable GUI?

Asked by 5 years ago

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

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
5 years ago
Edited 5 years ago

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!

0
Wait so, where do i put the reaction for the GUI to enable? jetpush123 2 — 5y
0
ah, i see the "replacewithgui" my bad. im just blind aha jetpush123 2 — 5y
0
Didnt work, thanks though. ;-; jetpush123 2 — 5y
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) Godlydeathdragon 227 — 5y
View all comments (2 more)
0
if this works im gonna be mad at myself jetpush123 2 — 5y
0
lmao @godlydeath I saw that, fixed the typo. moo1210 587 — 5y
Ad

Answer this question