Hello, I am trying to make a toggle script for a car's headlights. For some reason, there is nothing happening if I press L. No errors in the console.
local toggle = false -- false is Off; true is On
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
print("L was pressed")
if toggle == false then
toggle = true
script.Parent.Enabled = true
else
toggle = false
script.Parent.Enabled = false
end
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.L)

4 comments
I just ran this from a localscript and it worked and printed "L was pressed" for me. Where is your script located?
Make sure the script is being ran in a place where LocalScripts will run properly
Use a tutorial. I can't say where it goes but you need to use UserInputService.
The most helpful anwser - no!