-------------------------


 
mouse.KeyDown:connect(function (key)
    key = string.lower(key)
				if key == "k" then --Camera controls
				        if cam == ("car") then
							Camera.CameraSubject = player.Character.Humanoid
							Camera.CameraType = ("Custom")
							cam = ("freeplr")
							Camera.FieldOfView = 70
						elseif cam == ("freeplr") then
							Camera.CameraSubject = player.Character.Humanoid
							Camera.CameraType = ("Attach")
							cam = ("lockplr")
							Camera.FieldOfView = 45
				        elseif cam == ("lockplr") then
							Camera.CameraSubject = carSeat
							Camera.CameraType = ("Custom")
							cam = ("car")
							Camera.FieldOfView = 70
				        end
				
											elseif key == "g" then --Window controls
		 if carSeat.Wipers.Value == false then 
			carSeat.Wipers.Value = true
		 else carSeat.Wipers.Value = false
		 end
						elseif key == "[" then -- volume down
			if carSeat.Parent.MP.Volume.Value > 0 then
				carSeat.Parent.MP.Volume.Value = carSeat.Parent.MP.Volume.Value - 2
			end
		elseif key == "]" then -- volume up
			if carSeat.Parent.MP.Volume.Value < 500000 then
				carSeat.Parent.MP.Volume.Value = carSeat.Parent.MP.Volume.Value + 2
			end	
				elseif key == "u" then --Window controls
				 if windows == false then 
					winfob.Visible = true
					windows = true
				 else windows = false
					winfob.Visible = false
				 end
			end
end)

winfob.FL.Lock.MouseButton1Click:connect(function() --Window
 if carSeat.WindowFL.Value == false then 
  carSeat.WindowFL.Value = true
  carSeat.Parent.Misc.FL.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.FL.Window.SS.Motor.DesiredAngle - 0.20
 else carSeat.WindowFL.Value = false
  carSeat.Parent.Misc.FL.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.FL.Window.SS.Motor.DesiredAngle + 0.20
 end
end)

winfob.FR.Lock.MouseButton1Click:connect(function() --Window
 if carSeat.WindowFR.Value == false then 
  carSeat.WindowFR.Value = true
  carSeat.Parent.Misc.FR.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.FR.Window.SS.Motor.DesiredAngle + 0.20
 else carSeat.WindowFR.Value = false
  carSeat.Parent.Misc.FR.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.FR.Window.SS.Motor.DesiredAngle - 0.20
 end
end)
 
winfob.RL.Lock.MouseButton1Click:connect(function() --Window
 if carSeat.WindowRL.Value == false then 
  carSeat.WindowRL.Value = true
  carSeat.Parent.Misc.RL.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.RL.Window.SS.Motor.DesiredAngle - 0.20
 else carSeat.WindowRL.Value = false
  carSeat.Parent.Misc.RL.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.RL.Window.SS.Motor.DesiredAngle + 0.20
 end
end)

winfob.RR.Lock.MouseButton1Click:connect(function() --Window
 if carSeat.WindowRR.Value == false then 
  carSeat.WindowRR.Value = true
  carSeat.Parent.Misc.RR.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.RR.Window.SS.Motor.DesiredAngle + 0.20
 else carSeat.WindowRR.Value = false
  carSeat.Parent.Misc.RR.Window.SS.Motor.DesiredAngle = carSeat.Parent.Misc.RR.Window.SS.Motor.DesiredAngle - 0.20
 end
end)

HUB.Limiter.MouseButton1Click:connect(function() --Ignition
 if carSeat.IsOn.Value == false then
	carSeat.IsOn.Value = true
	carSeat.Startup:Play()
	carSeat.Parent.Body.Lights.Int.Material = "SmoothPlastic"
	carSeat.Parent.Body.SmokeA.ParticleEmitter.Enabled = true
	carSeat.Parent.Body.Dash.Screen.G.Enabled = true
	carSeat.Parent.Body.Dash.DashSc.G.Enabled = true
	carSeat.Parent.Body.Lights.Runner.Material = "Neon"		
else
	carSeat.IsOn.Value = false
	carSeat.Parent.Body.SmokeA.ParticleEmitter.Enabled = false
	carSeat.Parent.Body.Dash.Screen.G.Enabled = false
	carSeat.Parent.Body.Dash.DashSc.G.Enabled = false
	carSeat.Parent.Body.Lights.Runner.Material = "SmoothPlastic"		
end
end)

TR.SN.MouseButton1Click:connect(function() --Show tracker names
	script.Parent.Names.Value = true
end)

TR.HN.MouseButton1Click:connect(function() --Hide tracker names
	script.Parent.Names.Value = false
end)

carSeat.Indicator.Changed:connect(function()
	if carSeat.Indicator.Value == true then
		script.Parent.Indicator:Play()
	else
		script.Parent.Indicator2:Play()
	end
end)

		--raycasting BMS
	local snsrs = carSeat.Parent.Body.Sensors
	local rel = snsrs.BMSL.RayEnd
	local rl = snsrs.BMSL.RayStart
	local rer = snsrs.BMSR.RayEnd
	local rrr = snsrs.BMSR.RayStart
	
	if workspace:FindPartOnRay(Ray.new(rel.CFrame.p,(rel.CFrame.p-rl.CFrame.p).unit * 18)) then
		carSeat.Parent.Misc.FL.Door.Mirror.Light.G.Enabled = true
	else carSeat.Parent.Misc.FL.Door.Mirror.Light.G.Enabled = false
	end
	
	if workspace:FindPartOnRay(Ray.new(rer.CFrame.p,(rer.CFrame.p-rrr.CFrame.p).unit * 18)) then
		carSeat.Parent.Misc.FR.Door.Mirror.Light.G.Enabled = true
	else carSeat.Parent.Misc.FR.Door.Mirror.Light.G.Enabled = false
	end
	


carSeat.LI.Changed:connect(function()
	if carSeat.LI.Value == true then
		carSeat.Parent.Body.Dash.DashSc.G.Left.Visible = true
		script.Parent.HUB.Left.Visible = true
	else
		carSeat.Parent.Body.Dash.DashSc.G.Left.Visible = false
		script.Parent.HUB.Left.Visible = false
	end
end)

carSeat.RI.Changed:connect(function()
	if carSeat.RI.Value == true then
		carSeat.Parent.Body.Dash.DashSc.G.Right.Visible = true
		script.Parent.HUB.Right.Visible = true
	else
		carSeat.Parent.Body.Dash.DashSc.G.Right.Visible = false
		script.Parent.HUB.Right.Visible = false
	end
end)

while wait() do
	carSeat.Parent.Body.Dash.Screen.G.Time.Text = game.Lighting.TimeOfDay
	carSeat.Parent.Body.Dash.DashSc.G.Time.Text = game.Lighting.TimeOfDay
	carSeat.Parent.Body.Dash.DashSc.G.Speed.Text = math.floor(carSeat.Velocity.magnitude*((10/12) * (60/88)))
	script.Parent.HUB.Time.Text = game.Lighting.TimeOfDay
	

end