"Unable to assign property CFrame. CoordinateFrame expected, got table"

i’m trying to make a camera script it has a table of different very specific cframes for different cameraparts, but i keep getting the same error :frowning: i’m not understanding the error and i’ve been researching for quite a while before coming here i would really appreciate help :folded_hands: (i apologize if my explanation is poor i dont post here very often)


-- variables
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local reps = game:GetService("ReplicatedStorage")

local char = player.Character or player.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart")

-- setting camera
camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 65

-- camera parts
local camParts = {
	tutorialcamPart = workspace.tutorial:WaitForChild("tutorialCameraPart"),
	notosofficecamPart = workspace.chapter1.notosoffice:WaitForChild("desk"),
}

-- cframes of the camera positions
local camCFrames =
	{
		[1] = {CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[2] = {CFrame.new(camParts.tutorialcamPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[3] = {CFrame.new(camParts.notosofficecamPart.Position) * CFrame.new(3, 2, 4) * CFrame.Angles(math.rad(-9), math.rad(25), math.rad(2))}
	}

-- variable for the camera pos in use
local camInUse = false

-- function to change the camera pos in use
local function changeCam(cam)
	camInUse = camCFrames[cam]
end

-- using the camera
game:GetService("RunService").RenderStepped:Connect(function()
	camera.CFrame = camInUse -- the line the error is on
end)

changeCam(1) -- change the camera
2 Likes
{CFrame.new()} -- Wrong
CFrame.new() -- Right

or change

camInUse = camCFrames[cam][1]
3 Likes

this does stop the error :tada: :tada: but now my camera only stays at the first position of where the rootpart spawned instead of following it

i also moved the changeCam(1) to be above the renderstepped and it still has the same problem :frowning:

If you want the position to change each time, you should put your function in a loop (connection)

-- cframes of the camera positions
local camCFrames =
	{
		[1] = {CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[2] = {CFrame.new(camParts.tutorialcamPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[3] = {CFrame.new(camParts.notosofficecamPart.Position) * CFrame.new(3, 2, 4) * CFrame.Angles(math.rad(-9), math.rad(25), math.rad(2))}
	}

-- variable for the camera pos in use
local camInUse = false

-- function to change the camera pos in use
local function changeCam(cam)
	camCFrames = {
		[1] = {CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[2] = {CFrame.new(camParts.tutorialcamPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[3] = {CFrame.new(camParts.notosofficecamPart.Position) * CFrame.new(3, 2, 4) * CFrame.Angles(math.rad(-9), math.rad(25), math.rad(2))}
	}
	
	camInUse = camCFrames[cam][1]
end

-- using the camera
local totalTime = 0
local timeForPosition = 1
local currentCameraState = 1

game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
	totalTime += deltaTime
	
	if timeForPosition / totalTime < 1 then return end
	
	totalTime = 0
	currentCameraState = if currentCameraState + 1 <= #camCFrames then currentCameraState + 1 else 1
	
	changeCam(currentCameraState)
	
	camera.CFrame = camInUse -- the line the error is on
end)

changeCam(1) -- change the camera

If you want to change it yourself, update only this function.

local function changeCam(cam)
	camCFrames = {
		[1] = {CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[2] = {CFrame.new(camParts.tutorialcamPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0)},
		[3] = {CFrame.new(camParts.notosofficecamPart.Position) * CFrame.new(3, 2, 4) * CFrame.Angles(math.rad(-9), math.rad(25), math.rad(2))}
	}
	
	camInUse = camCFrames[cam][1]
end

Any reason for it being a table of tables?

If not you should just make it a table of CFrames:

local camCFrames =
	{
		[1] = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0),
		[2] = CFrame.new(camParts.tutorialcamPart.Position) * CFrame.new(0, 12, 12) * CFrame.Angles(math.rad(-45), 0, 0),
		[3] = CFrame.new(camParts.notosofficecamPart.Position) * CFrame.new(3, 2, 4) * CFrame.Angles(math.rad(-9), math.rad(25), math.rad(2))
	}

Also the CFrames are created once and never updated.

2 Likes
for I = 0, #camCFrames, 1 do
     task.wait(2) -- however long it takes for the subject to move from position to position
     camInUse = camCFrames[cam][I]
end

I don’t know what the cam is or where it comes from

i meant that i wanted the camera to follow the PLAYER when its set to the first camera cframe not to switch between all cameras :sad_but_relieved_face: i realize that this happens because the variable of the player is set outside of the function and therefore is set as the spawn position of the player but i dont know how to fix this

yeah that was just me not knowing how to script :frowning:

2 Likes

i ended up figuring this one out
thank you all for the help !!

2 Likes

No worries man, even if I didn’t have an exact solution I hope to have helped you write better code.
Best of luck on your journey!

1 Like

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