Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Toggle script for headlights not working?

Asked by 4 years ago

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)
0
I just ran this from a localscript and it worked and printed "L was pressed" for me. Where is your script located? MrLonely1221 701 — 4y
0
Make sure the script is being ran in a place where LocalScripts will run properly MrLonely1221 701 — 4y
0
Use a tutorial. I can't say where it goes but you need to use UserInputService. PrismaticFruits 842 — 4y
0
The most helpful anwser - no! squidiskool 208 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Gave up on this.

Ad

Answer this question