The code is inside a script of a VehicleSeat
local seat = script.Parent
local LightPart = script.Parent.Parent.LightParts
local on = false
seat.Changed:Connect(function(ch)
if ch == "Occupant" then
if seat.Occupant then
local player = game.Players:FindFirstChild(seat.Occupant.Parent.Name) --The occupant is the humanoid, the humanoid.Parent is the player's character
--Your code here
game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
if key == "l" then
if on == true then
on = false
LightPart.HeadLightPart.Material = Enum.Material.SmoothPlastic
LightPart.HeadLightPart2.Material = Enum.Material.SmoothPlastic
else
LightPart.HeadLightPart.Material = Enum.Material.Neon
LightPart.HeadLightPart2.Material = Enum.Material.Neon
end
end
end)
end
end
end)

6 comments
Is this a Server Script?
LocalPlayer doesn't work in Server Scripts. Instead of game.Players.LocalPlayer you should use your already defined variable "player"
I posted a LocalScript version on your previous question, use that instead
It only works if I put it inside StarterCharacterScripts, then how am I gonna make the keybind work?
You can put it inside StarterPack, StarterPlayerScripts (and StarterGui) too
I'm trying to make a cars headlights turn on, and what if there's another car with the same model name?