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

Weird keydown not working? [UNANSWERED!]

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

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)

1 comment

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 :(

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