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

Weird keydown not working? [UNANSWERED!]

Asked by 9 years ago

Hi guys! this script works but only if I press Shift and M making it an uppercase. Any ideas?? Thanks

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
gui = script.Parent.Menu.Frame
Open = false
Mouse.KeyDown:connect(function(key)
if string.lower(key) == "m" then
  gui.Visible = not gui.Visible
 end
end)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

I'm unaware why your code would be behaving the way you describe it is.. perhaps you have caps lock on? I don't know, but i'm going to suggest an alternative method for you.

Use UserInputService, with the InputBegan function.

The InputBegan function listens for ANY user input.. and it returns what user input was, well, inputted. So what you can do with this function is compare the returned value(the parameter)'s KeyCode with a KeyCode Enum, like; Enum.KeyCode.M.

--UserInputService
local uis = game:GetService('UserInputService')
--Gui
local gui = script.Parent.Menu.Frame

--InputBegan
uis.InputBegan:connect(function(input)
    --Compare KeyCodes
    if input.KeyCode == Enum.KeyCode.M then
        --Toggle visibility of gui
        gui.Visible = not gui.Visible
    end
end)
0
Thanks very much! But it still doesn't work :( I do not have Caps lock on and it only works with Shift and M again :( :( Any ideas? It is so weird? I have tried loads of different ways :( jjwood1600 215 — 9y
Ad

Answer this question