I'm ultimately trying to make a localscript that prevents the player from using the W and S keys to move forward and backward (platform game). For now, though, I'm trying to get the concept of just getting a script to recognize when these keys are pressed. My goal with this specific script is to make it print "q off" and "q on" when I press the Q key.
I probably did this all wrong because I'm new to Lua, but I gave it my best shot. No error messages, but it doesn't work. The following code is in a local script.
local player = game.Players.LocalPlayer
deb = false
input = game:GetService("UserInputService")
actionkey = Enum.KeyCode.Q
function pressQ(key)
if key == actionkey and deb == false then
print("q on")
deb = true
end
if key == actionkey and deb == true then
print("q off")
deb = true
end
end
input.InputBegan:Connect(pressQ)
Thanks for any help!

5 comments
I made the changes you suggested (thanks so much), but it's still not working when I test it in Studio. Any ideas?
hmm
there might be other factors at play here
try using remote events
MC, could you answer this question with an example of how to use remote events? I've never coded with one before.