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

Toggle script for headlights not working?

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

0

I just ran this from a localscript and it worked and printed "L was pressed" for me. Where is your script located?

0

Make sure the script is being ran in a place where LocalScripts will run properly

0

Use a tutorial. I can't say where it goes but you need to use UserInputService.

0

The most helpful anwser - no!

1 answer

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