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

Does not read KeyDown?

In a local script that I am working on there is a section that is suppose to find what key was pressed then see if it is the key that is suppose to be pressed in a textBox e.g user types in something then when he is done he clicks the outside to remove the cursor and presses "r", but it is not working. I don't get any error codes or anything.

local Player = game.Players.LocalPlayer -- for the key down events
local Mouse = Player:GetMouse()
 
function rButtonCheck() -- checks to see if the user pressed 'r'
	if button == "r" then
		print("player pressed return")
	end
	
end

Mouse.KeyDown:connect(rButtonCheck,button)

1 answer

✓ Accepted answer

The connect method only takes on argument, which is the function to fire (rButtonCheck in this case).


Parameters that the event pass are passed to that function when it is called. You're trying to use button here but you aren't using it as the parameter of the function:

function rButtonCheck(button)

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