Tweening Cameras Position and Rotation

Currently trying to rotate and position the camera.
Its a local script inside StarterPlayerScripts.
It only gives an Error in Line 11

Error:

Code:

task.wait(2)

local part = game.Workspace.ControlBlock2.ClickModel.ClickPart
local click = part.ClickDetector
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(2)

click.MouseClick:Connect(function(plr)
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Scriptable
	local tween = tweenService:Create(camera, info,{CFrame = CFrame.new(part.CFrame.Position.X, part.CFrame.Position.Y + 100, part.CFrame.Position.Z), CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(0))})
	tween:Play()
	click:Destroy()
end)

Your problematic line of code is here.
Your code is currently as follows, with some annotation:

{
CFrame = CFrame.new(part.CFrame.Position.X, part.CFrame.Position.Y + 100, part.CFrame.Position.Z), 
[nil?] = CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(0))
}

. Presumably, you intended on doing something with the CFrame created with fromEulerAnglesXYZ rather than attempting to put it in an entirely different, nonexistent index in the dictionary, however, you can just omit that part entirely since your rads are equal to zero in this current version.

1 Like

But what if I want to change the Orientation/Rotation? What would I have to write then?

instead of adding a new element into the tween array, putting both CFrame constructors and combining them with * adds both the positional and rotational coordinates

CFrame = CFrame.new(part.CFrame.Position.X, part.CFrame.Position.Y + 100, part.CFrame.Position.Z) * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(0))
2 Likes

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