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

car lights key bind?

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)

3 comments

0

put in codebox

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.

0

i bet u used yt i saw that code

1 answer

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)

2 comments

0

im going to try it, Hope it works

0

it didn't work

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