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

J for turning on off lights in vehicles?

I am making a DOT (Department of transportation) ford f350, the lights flash but I ney a keybind for on/off lighting, but i have no idea where to put it I know the script Enum.KeyCode.(button)

1 answer

✓ Accepted answer

Before you connect this code, make sure that the player is actually in the car, else they'll be able to turn the lights on/off even if they're not driving. This should also go in a local script. This script also assumes that you have a function for turning the lights on and off. Didn't test this so watch out for spelling mistakes.

local UIS = game:GetService("UserInputService")
local LightsAreOn = false

UIS.InputBegan:Connect(function(Input, GSE)
	if Input.Keycode = Enum.KeyCode.J then
		if LightsAreOn then
			LightsOn()
			LightsAreOn = true
		else
			LightsOff()
			LightsAreOn = false
		end
	end
end)

2 comments

0

Thanks, Everything is spelled right, put this in the a chassi or lightbar?

0

Doesn't matter. Just check if the player is driving before you run the code. Also this probably won't work if filtering enabled is on, so use RemoteEvents to turn off/on the lights if your games uses FE.

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