local players = game:GetService("Players") local runService = game:GetService("RunService") local inputService = game:GetService("UserInputService") local player = players.LocalPlayer local vehicles = workspace:WaitForChild("Vehicles") local atvs = workspace:WaitForChild("ATVs") local enabled = false local activeVehicle local cameraTarget local cameraOffset local cameraTargetRotation local cameraDistance local savedCameraSubject local function getVehicle() local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") local seat = humanoid and humanoid.SeatPart if not seat or not seat:IsA("VehicleSeat") or seat.Name ~= "DriverSeat" then return end local vehicle = seat.Parent if vehicle and (vehicle.Parent == vehicles or vehicle.Parent == atvs) then return vehicle, seat end end local function getDirection(camera) local direction = Vector3.zero if inputService:IsKeyDown(Enum.KeyCode.W) then direction += camera.CFrame.LookVector end if inputService:IsKeyDown(Enum.KeyCode.S) then direction -= camera.CFrame.LookVector end if inputService:IsKeyDown(Enum.KeyCode.D) then direction += camera.CFrame.RightVector end if inputService:IsKeyDown(Enum.KeyCode.A) then direction -= camera.CFrame.RightVector end return direction.Magnitude > 1 and direction.Unit or direction end local function resetCamera() local camera = workspace.CurrentCamera local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") local subject = savedCameraSubject if humanoid and not humanoid.SeatPart then subject = humanoid end if subject and subject.Parent then camera.CameraSubject = subject elseif humanoid then camera.CameraSubject = humanoid end if cameraTarget then cameraTarget:Destroy() end activeVehicle = nil cameraTarget = nil cameraOffset = nil cameraTargetRotation = nil cameraDistance = nil savedCameraSubject = nil end local function attachCamera(vehicle, seat) local camera = workspace.CurrentCamera local subject = camera.CameraSubject local source = typeof(subject) == "Instance" and subject:IsA("BasePart") and subject or seat local target = Instance.new(source:IsA("VehicleSeat") and "VehicleSeat" or "Part") target.Name = "VehicleFlyCamera" target.Size = source.Size target.Transparency = 1 target.Anchored = true target.CanCollide = false target.CanQuery = false target.CanTouch = false target.CFrame = source.CFrame target.Parent = workspace savedCameraSubject = subject cameraTarget = target cameraOffset = vehicle:GetPivot():PointToObjectSpace(source.Position) cameraTargetRotation = source.CFrame.Rotation cameraDistance = (camera.CFrame.Position - camera.Focus.Position).Magnitude camera.CameraSubject = target end inputService.InputBegan:Connect(function(input, typing) if not typing and input.KeyCode == Enum.KeyCode.V then enabled = not enabled if not enabled then resetCamera() end end end) inputService.InputChanged:Connect(function(input) if enabled and cameraDistance and input.UserInputType == Enum.UserInputType.MouseWheel then local zoomStep = math.max(1, cameraDistance * 0.15) cameraDistance = math.clamp( cameraDistance - input.Position.Z * zoomStep, player.CameraMinZoomDistance, player.CameraMaxZoomDistance ) end end) runService.RenderStepped:Connect(function(deltaTime) if not enabled then return end local vehicle, seat = getVehicle() if not vehicle then if activeVehicle then resetCamera() end return end local camera = workspace.CurrentCamera local pivot = vehicle:GetPivot() if vehicle ~= activeVehicle then resetCamera() activeVehicle = vehicle attachCamera(vehicle, seat) end local focusPosition = camera.Focus.Position local cameraOffsetFromFocus = camera.CFrame.Position - focusPosition if cameraOffsetFromFocus.Magnitude > 0 then local cameraPosition = focusPosition + cameraOffsetFromFocus.Unit * cameraDistance camera.CFrame = CFrame.new(cameraPosition) * camera.CFrame.Rotation end local direction = getDirection(camera) local speed = inputService:IsKeyDown(Enum.KeyCode.LeftShift) and 240 or 120 local position = pivot.Position + direction * speed * deltaTime local targetPivot = CFrame.new(position) * camera.CFrame.Rotation local targetPosition = targetPivot:PointToWorldSpace(cameraOffset) vehicle:PivotTo(targetPivot) cameraTarget.CFrame = CFrame.new(targetPosition) * cameraTargetRotation local body = vehicle:FindFirstChild("Body") local base = body and body:FindFirstChild("Base") or seat base.AssemblyLinearVelocity = Vector3.zero base.AssemblyAngularVelocity = Vector3.zero end)