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

car lights key bind?

Asked by 5 years ago
Edited 5 years ago

how do i make a script to turn on car lights i tried to find a video about it but can't find it plz help me. i have this coding from a other car but i can't get it to work

local m = game.Players.LocalPlayer:GetMouse()
db = true
m.KeyDown:connect(function(k)
    k = k:lower()
    if k == "l" then
        if db == true then
            script.Parent.Parent.Body.Lichten.Koplampen.Part.Lighto.Enabled = true
            script.Parent.Parent.Body.Lichten.Koplampen.Part.Point.Enabled = true
            db = false
            wait(3)
            db = true
        end
    end

end)

0
put in codebox yHasteeD 1819 — 5y
0
You can't rely on a tutorial existing for everything.. Tutorials are just that: tutorials. You are kind of close though, so don't give up trying. Don't use KeyDown, use UserInputService. Optikk 499 — 5y
0
i bet u used yt i saw that code HappyTimIsHim 652 — 5y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

It depends what kind of lights your car use. If they are SpotLights, just change the Enabled for them like you did, but make sure you use the correct path to them.

Also, use UserInputService or ContextActionService for keybinds.

Example:

local lights = --path to the parent of car's lights
game:GetService"UserInputService".InputBegan:Connect(function(iobj, gp)
    if not gp then return end --if they are i.e. typing in a textbox
    if iobj.KeyCode == Enum.KeyCode.L and not debounce then
        for i,v in pairs(lights:GetChildren()) do
            if v.ClassName == "SpotLight" then
                v.Enabled = not v.Enabled --toggle it
            end
        end
    end
end)
0
im going to try it, Hope it works Thomasdj01 -22 — 5y
0
it didn't work Thomasdj01 -22 — 5y
Ad

Answer this question