How to orient/rotate the camera used in a viewport frame?

How would I go about scripting this? I’ve been trying to figure this out for the last few days, but nothing I have tried will work.

A reference to further explain what I want to do (from Jailbreak)
ViewPortFrameReference

Have you tried looking at a good community resource?

It’s basically not bad to make, to implement this you have to rotate the “Car” Model or mesh

local viewportFrame = script.Parent
local car = viewportFrame:WaitForChild("CarModel")  -- If your car is not a model, then make sure you group it and set primarypart to the primarypart to the car mesh

-- setup for camera
local camera = Instance.new("Camera")
camera.Parent = viewportFrame
viewportFrame.CurrentCamera = camera

camera.CFrame = CFrame.new(Vector3.new(0, 5, 20), car.PrimaryPart.Position)

local function rotateCar()
	while true do
		local rotation = .5  -- rotation is in radients so if you want it to rotate smoothly i recommend going about 0.01 and set the yield to 0.01
		local rotationAxis = Vector3.new(0, 1, 0)
		car:PivotTo(car.PrimaryPart.CFrame * CFrame.Angles(0, rotation, 0))
		task.wait(.5)
	end
end

-- Function Call
rotateCar()

Let me know if you need help!

maybe you could make the object rotate instead of the camera orbiting? The advantage of that would be that you could use a tween instead of render stepped.

If that is not possible heres another solution:
If you have a lot of parts in your model, then its best to have cframe thats rotating and then you set an offset each time. This is what I mean:

local cam -- define your camera in the viewport
local Offset = CFrame.new(0,3,10)
local Centre = CFrame.new(0,0,0)
local runSer = game:GetService("RunService")

runSer.RenderStepped:Connect(function(delta)
	Centre = Centre*CFrame.Angles(0,math.rad(2*60*delta),0) -- delta to make sure that it does not rotate faster for people with better performance.
	cam.CFrame = Centre * Offset
end)

you can use one render stepped event and for loop through all frames if you have multiple.

I hope this helped at least a bit!

Edit: If you don’t understand what I mean feel free to ask!