"Position cannot be assigned to" error in my module

Hey all. I am not too sure what this error actually means, as it seems to end abruptly without telling me what “position cannot be assigned to”. This error is referring to the line: self.Camera.CFrame.Position = Vector3.new(xPos, yPos, zPos). Any help would be great :smiley:

This is the code down below:

local RunService = game:GetService("RunService")

local function quadBezier(t, p0, p1, p2)
	return (1 - t)^2 * p0 + 2 * (1 - t) * t * p1 + t^2 * p2

local CameraMovement = {}
CameraMovement.__index = CameraMovement

function CameraMovement.new(camera)
	local self = setmetatable({}, CameraMovement)
	self.Camera = camera
	camera.CameraType = Enum.CameraType.Scriptable
	return self

function CameraMovement:QuadFocus(p0, p1, p2, focusPart)
	for i = 0, 1, 0.001 do
		local xPos = quadBezier(i, p0.Position.X, p1.Position.X, p2.Position.X)
		local yPos = quadBezier(i, p0.Position.Y, p1.Position.Y, p2.Position.Y)
		local zPos = quadBezier(i, p0.Position.Z, p1.Position.Z, p2.Position.Z)
		self.Camera.CFrame.Position = Vector3.new(xPos, yPos, zPos)
		self.Camera.CFrame = CFrame.new(self.Camera.CFrame.Position, focusPart.Position)

return CameraMovement

Simple, the position property of cframe is read only. Just convert your vector3 to a cframe by replacing the word ‘Vector3’ for ‘CFrame’ and the assign it to the CFrame property of the camera.


Oh ok, thanks. I never knew that it was read only lmao

1 Like

Abcreator nailed it, you can probably just do something like this:

self.Camera.CFrame = CFrame.new(Vector3.new(xPos, yPos, zPos)) * (self.Camera.CFrame - self.Camera.CFrame.Position)