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

 
mouse.KeyDown:connect(function (key)
    key = string.lower(key)
			if key == "k" then --Camera controls
			        if cam == ("car") then
						cam = ("first")
			        elseif cam == ("first") then
						Camera.CameraSubject = carSeat
						Camera.CameraType = ("Custom")
						cam = ("car")
						Camera.FieldOfView = 70
					end
			elseif key == "z" then
				left = not left
				LeftInd()
			elseif key == "c" then
				right = not right
				RightInd()
			elseif key:byte() == 48 then
			script.Parent.rBrake.Value = true
			elseif key == "l" then
				if carSeat.Lights.Value == false then
					carSeat.Lights.Value = true
					carSeat.Parent.Body.Lights.Lights.HL.L.Enabled = true
					carSeat.Parent.Body.Lights.Lights.HL.G.Enabled = true
					carSeat.Parent.Body.Lights.Lights.HR.L.Enabled = true
					carSeat.Parent.Body.Lights.Lights.HR.G.Enabled = true
				else
					carSeat.Lights.Value = false
					carSeat.Parent.Body.Lights.Lights.HL.L.Enabled = false
					carSeat.Parent.Body.Lights.Lights.HL.G.Enabled = false
					carSeat.Parent.Body.Lights.Lights.HR.L.Enabled = false
					carSeat.Parent.Body.Lights.Lights.HR.G.Enabled = 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 < 100 then
					carSeat.Parent.MP.Volume.Value = carSeat.Parent.MP.Volume.Value + 2
				end	
		end
end)
mouse.KeyUp:connect(function(key)
	if key:byte() == 48 then
		script.Parent.rBrake.Value = false
	end
end)
HUB.Limiter.MouseButton1Click:connect(function() --startup
 if carSeat.IsOn.Value == false then
	carSeat.IsOn.Value = true
	carSeat.Startup:Play()
else
	carSeat.IsOn.Value = false
end
end)

standButton.MouseButton1Click:connect(function()
        if ks.CanCollide == false then
			carSeat.Parent.Body.KW.Nein.Transparency = 0
			carSeat.Parent.Body.KW.lamfo.Transparency = 0
			ks.CanCollide = true
        elseif ks.CanCollide == true then
			carSeat.Parent.Body.KW.Nein.Transparency = 1
			carSeat.Parent.Body.KW.lamfo.Transparency = 1
			ks.CanCollide = false
        end
end)
function LeftInd()
	if left == true then
		repeat
			carSeat.Parent.Body.Lights.L.G.Enabled = true
			carSeat.Parent.Body.Lights.L2.G.Enabled = true
			carSeat.Parent.Body.Lights.Lights.L.G.Enabled = true
			script.Parent.Indicator:Play()
			script.Parent.HUB.Left.Visible = true
			wait(1/3)
			carSeat.Parent.Body.Lights.L.G.Enabled = false
			carSeat.Parent.Body.Lights.L2.G.Enabled = false
			carSeat.Parent.Body.Lights.Lights.L.G.Enabled = false
			script.Parent.Indicator2:Play()
			script.Parent.HUB.Left.Visible = false
			wait(1/3)
		until left == false
		carSeat.Parent.Body.Lights.L.G.Enabled = false
		carSeat.Parent.Body.Lights.L2.G.Enabled = false
		carSeat.Parent.Body.Lights.Lights.L.G.Enabled = false
	end
end
function RightInd()
	if right == true then
		repeat
			carSeat.Parent.Body.Lights.R.G.Enabled = true
			carSeat.Parent.Body.Lights.R2.G.Enabled = true
			carSeat.Parent.Body.Lights.Lights.R.G.Enabled = true
			script.Parent.Indicator:Play()
			script.Parent.HUB.Right.Visible = true
			wait(1/3)
			carSeat.Parent.Body.Lights.R.G.Enabled = false
			carSeat.Parent.Body.Lights.R2.G.Enabled = false
			carSeat.Parent.Body.Lights.Lights.R.G.Enabled = false
			script.Parent.Indicator2:Play()
			script.Parent.HUB.Right.Visible = false
			wait(1/3)
		until right == false
		carSeat.Parent.Body.Lights.R.G.Enabled = false
		carSeat.Parent.Body.Lights.R2.G.Enabled = false
		carSeat.Parent.Body.Lights.Lights.R.G.Enabled = false
	end
end
game:GetService("RunService").RenderStepped:connect(function()
	if carSeat.IsOn.Value == true and cam == "first" then
		local XLook=math.max(math.min(((mouse.X-(mouse.ViewSizeX/2))/300)^3,1),-1)
		local YLook=math.max(math.min(((mouse.Y-(mouse.ViewSizeY/2))/300)^3,1),-1)
		local LookOffset=player.Character.Head.CFrame:toWorldSpace(CFrame.new(0,.1,-.5)*CFrame.Angles(-YLook,-XLook,0))
		Camera.CameraType="Scriptable"
		Camera.CameraSubject=player.Character.Humanoid
		Camera.CoordinateFrame=LookOffset
		player.CameraMaxZoomDistance=0
	else
		Camera.CameraSubject = carSeat
		Camera.CameraType = ("Custom")
		cam = ("car")
		player.CameraMaxZoomDistance=100
	end
end)
script.Parent.CarSeat.Value.ChildRemoved:connect(function(child)
	Camera.CameraType="Custom"
	Camera.CameraSubject=player.Character.Humanoid
	player.CameraMaxZoomDistance=100
	script:Destroy()
end)
while wait() do
	local g = carSeat.BodyGyro
	if W.Value == true and carSeat.Throttle == 1 then
		Whel = 0.4
	elseif W.Value == true and carSeat.Throttle == -1 then
		Whel = -0.4
	else
		Whel = 0
	end
	g.CFrame=CFrame.new(carSeat.CFrame.p,carSeat.CFrame.p+carSeat.CFrame.lookVector)*CFrame.Angles(Whel,(-carSeat.Steer*math.min(carSeat.Velocity.magnitude/(carSeat.MxSpd.Value),diff)*math.pi/4)*(carSeat.Velocity.magnitude/(carSeat.MxSpd.Value/2)),-carSeat.Steer*math.min(carSeat.Velocity.magnitude/(carSeat.MxSpd.Value/2),1)*math.pi/5)