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)
It depends what kind of lights your car use. If they are SpotLight
s, 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)