Tweening camera's CFrame does not work for me, I have two conflicting errors?

I am trying to make a camera’s orientation go up, but when I try to use CFrame.new, I get this error:

invalid argument #1 to ‘new’ (Vector3 expected, got CFrame)

So I changed “CFrame” to Vector3.new, and got a different error:

TweenService:Create property named ‘CFrame’ cannot be tweened due to type mismatch (property is a ‘CoordinateFrame’, but given type is ‘Vector3’)

I don’t quite understand what this means. Does it expect me to use Vector3 but gives me an error if I use it?
Here is the piece of code that I have written. It is not the complete script, but only the part where I am manipulating the camera:

local camera = game.Workspace.CurrentCamera
local pos = CFrame.new(0, 0, 0)
local lookat = CFrame.new(10, 0, 0)
local goal = {}
goal.CFrame = CFrame.new(pos, lookat)
local tweenInfo = TweenInfo.new(0.1)
local tween = TweenService:Create(camera, tweenInfo, goal)
tween:Play()

First of all, you are making the pos and rotation values CFrame values instead of Vector3’s. That should clear the first error because you don’t put two CFrame values into one. Also I tried it out and it worked perfectly fine after doing what I said. Here is a revised script:

local camera = game.Workspace.CurrentCamera
local pos = Vector3.new(0, 0, 0)
local lookat = Vector3.new(10, 0, 0)
local tweenInfo = TweenInfo.new(0.1)
local tween = TweenService:Create(camera, tweenInfo, {CFrame = CFrame.new(pos, lookat)})
tween:Play()

Hope this helps.
Tell me if this doesn’t work and I will try and think of something different.

1 Like

Using Vector3.new for the variables and putting the CFrame inside the tween creation parenthesis like you did solved the problem. Thank you very much, now the code works as it should

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.