Why can't I assign the position?

  • I wanted to make my camera up, like does 2D games. But when I used a part and changed the CameraSubject to it, the part couldn’t copy the players(Character) position, so I used instead the Camera in the Workspace but when I try assigning the position it doesn’t do its thing. Can someone help me?
local char:Model = script.Parent
local camera = workspace.Camera

local HIEGHTOFFSET = 6

local pos = {
	
	[1] = char.PrimaryPart.Position.X, -- X
	[2] = char.PrimaryPart.Position.Y*HIEGHTOFFSET, -- Y
	[3] = char.PrimaryPart.Position.Z -- Z
}

-- Loop
while true do
	camera.Focus.Position = Vector3.new(pos[1], pos[2], pos[3])
	wait(0)
end

Error:

Position cannot be assigned to
  • I haven’t yet though do the camera positioning to be more like a 2D game but I will figure it out sooner or later…
1 Like

you need to set the cameras type to scriptable, place this line above the loop

camera.CameraType = Enum.CameraType.Scriptable
1 Like

Let me try that out real quick.

When I placed it above the loop it still says the error.

Try

local character = script.Parent
local character = script.Parent
local camera = workspace.Camera

local HIEGHTOFFSET = 6

local pos = {
	
	[1] = character .PrimaryPart.Position.X, -- X
	[2] = character .PrimaryPart.Position.Y*HIEGHTOFFSET, -- Y
	[3] = character .PrimaryPart.Position.Z -- Z
}

-- Loop
while true do
	camera.Focus.Position = Vector3.new(pos[1], pos[2], pos[3])
	wait(0)
end

isn’t adding a : then adding your class still works?

1 Like

Yeah. But did it work when you remove the data type annotation?

Sadly no but what could cause the error though?

local char:Model = script.Parent
local camera = workspace.Camera

local HIEGHTOFFSET = 6

local pos = {
	
	[1] = char.PrimaryPart.Position.X, -- X
	[2] = char.PrimaryPart.Position.Y*HIEGHTOFFSET, -- Y
	[3] = char.PrimaryPart.Position.Z -- Z
}

-- Loop
while true do
	camera.CFrame = CFrame.new(pos[1], pos[2], pos[3])
	wait()
end

It still says the error, the error is saying its at camera.Focus.Position = Vector3.new(pos[1], pos[2], pos[3])

local character = script.Parent
local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable

local HIEGHTOFFSET = 6

local pos = {

	[1] = character.PrimaryPart.Position.X, -- X
	[2] = character.PrimaryPart.Position.Y * HIEGHTOFFSET, -- Y
	[3] = character.PrimaryPart.Position.Z -- Z
}

-- Loop
while true do
	camera.Focus = CFrame.new(pos[1], pos[2], pos[3])
	wait(0)
	print("DS")
end

maybe you didntcopy my code my code doesnt have such a line.

I want it to like change the Y Position of the Focus but it changes the Camera.Cframe

I don’t understand. Why are you using workspace.Camera and not workspace.CurrentCamera?

wait that one? Lemme try it :smiley:

It didn’t change anything what should I do?

hmm… Is it still the same error?

There were no errors but also it didn’t change anything

both are the same its like tomaeto tomaato

@PurpNinjalol this will work

local char:Model = script.Parent
local camera = workspace.Camera

local HIEGHTOFFSET = 6

-- Loop
while true do
	local pos = Vector3.new(char.PrimaryPart.Position.X,char.PrimaryPart.Position.Y*HIEGHTOFFSET,char.PrimaryPart.Position.Z)
	camera.Focus = CFrame.new(pos)
	wait()
end

@PurpNinjalol this is a local script, right?