Why cant I assign any value to my CFrameValue?

hello

so im having a problem assigning a number to the X Position inside of my CFrameValue
I dont know why, but I keep getting an error saying “X Cannot be assigned to”.

Heres the code:

local plr = game:GetService('Players').LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local hum = chr:WaitForChild('Humanoid')

local plrcamera = script.Parent:WaitForChild('PlayerCamera')
local coordinateposition = plrcamera.Coordinates.CoordinatePosition
local Camera = require(plrcamera:WaitForChild("Handler"))

local placeteleport = require(script:WaitForChild('ModuleScript'))
local objectname = 'PlaceTeleporter'

hum.Touched:Connect(function(object)
	if (object:IsA('Part') and object.Name == objectname) then
		local touched = object:WaitForChild('TouchBool')
		local place = object:WaitForChild('Place')
		local cameraxvalue = object:WaitForChild('CameraXValue')
		if touched.Value ~= true then
			coroutine.resume(coroutine.create(function()
				touched.Value = true
				task.wait()
				touched.Value = false
			end))
			placeteleport:TeleportPlayerPlace(place.Value)
			coordinateposition.Value.Position.X = 5
			Camera.loadcam()
		end
	end
end)

Am I doing anything wrong? I’ve never used a CFrameValue, so somebody please explain to me what the problem is here, this has been frustrating me for over an hour.

Thank you

1 Like

You cannot set individual properties of position types. So do this: coordinateposition.Value = CFrame.new(Vector3.new(5, coordinateposition.Value.Position.Y, coordinateposition.Value.Position.Z), coordinateposition.Value.Rotation)

1 Like

i tried this whole code and still got an error.;

i cant brainstorm any other solutions atm

1 Like

As IAmReallyNewb mentioned, CFrames are an immutable type, meaning you can’t modify them after you make them.

So you need to set the .Value to a new, modified CFrame.

An easy way to make CFrame like you want is:

local newCFrame = coordinateposition.Value + Vector3.new(5 - coordinateposition.Value.Position.X,0,0)
coordinateposition.Value = newCFrame
2 Likes

never knew that you could do that. thank you

2 Likes

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