Camera Rotation Tweening

Hey there dev forum.
So I got this camera bobble script with camera rotation effects that I’m trying to add.
I’ve tried lerping the rotation which didn’t do anything except making the camera point to the 0X and 0Y coordinates.
Now I’m trying to use Tweening.
I’ve been trying to get this working for the past 2 days.

This is the script I’m currently working with.

local runService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

function updateBobbleEffect()
	if humanoid.FloorMaterial ~= Enum.Material.Air then
		local currentTime = tick()
		if humanoid.MoveDirection.Magnitude > 0 then -- we are not standing still
			if not _G.Sprinting then -- we are walking

				local bobbleX = math.cos(currentTime * 5) * .1
				local bobbleY = math.abs(math.sin(currentTime * 6)) * .2
				
				local bobbleRotate = math.cos(currentTime * 2) * .1
				

				local bobblePos = Vector3.new(bobbleX, bobbleY, 0)
				local bobbleRot = Vector3.new(0, 0, bobbleRotate)
				
				local tweenInfo = TweenInfo.new(
					2, -- Time (seconds)
					Enum.EasingStyle.Quad, -- EasingStyle
					Enum.EasingDirection.Out, -- EasingDirection
					-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
					true, -- Reverses (false = no reverse)
					0 -- DelayTime (seconds)
				)

				humanoid.CameraOffset = humanoid.CameraOffset:Lerp(bobblePos, 0.15)
				local camRot = tweenService:Create(camera.CFrame.Rotation, tweenInfo, {Vector3 = bobbleRot})
				
				camRot:Play()

			elseif _G.Sprinting then -- we are sprinting

				humanoid.CameraOffset = humanoid.CameraOffset * 1

				local bobbleX = math.cos(currentTime * 7) * .4
				local bobbleY = math.abs(math.sin(currentTime * 9)) * .6
				
				local bobble = Vector3.new(bobbleX, bobbleY, 0)

				humanoid.CameraOffset = humanoid.CameraOffset:Lerp(bobble, .25)
			end
		else
			local speed = currentTime * 1 -- higher = faster bob
			local distance = .15 -- change for more drastic movement higher = more

			local bobbleY = math.abs(math.sin(speed)) * distance
			local bobble = Vector3.new(0, bobbleY, 0)

			humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .2)
		end
	end
end



runService.RenderStepped:Connect(updateBobbleEffect)

When I run it, there’s a bug in output.

Unable to cast value to Object

Any help is HIGHLY appreciated!

I think this post might help with your tweening: https://devforum.roblox.com/t/how-to-make-tween-service-rotate-my-part-by-360-degrees/533558

The reason why it gives you this error is because the first argument passed into the camRot tween is not an instance. You would have to put camera instead. However, with tweening you cannot directly tween the rotation/orientation of the camera. You would have to tween the camera with CFrames. It should look similar to this:

local camRot = tweenService:Create(camera, tweenInfo, {CFrame = CFrame.new(-- Give a vector3/position) * CFrame.Angles(math.rad(X), math.rad(Y), math.rad(Z))})

The usage of CFrame.Angles() can be replaced with other Cframe rotation methods too.