Adjusting an X position in a CFrame

I have basic understanding of CFrames and the variables that get passed through them. I want to adjust a CFrame X position variable while keeping all the other positions and angles the same.

I’m aware I can access the CFrame by CFrame.X and do CFrame.X+10 but then I can’t keep the rest of the positions and angles. Should I parse the entire CFrame and reconstruct it? or is there a better way to edit a CFrame variable? Any help would be appreciated.

Edit: I have looked at similar posts, but as far as I can see they did not cover this specific topic, it was more on angles.

1 Like

Hey! Good question, you can use

local X = Object.CFrame.X
local Y = Object.CFrame.Y
local Z = Object.CFrame.Z
Object.CFrame = CFrame.new(X+10,Y,Z)
2 Likes

Thanks for the response, but wouldn’t this just adjust the position without the angles being saved?

2 Likes

I edited the message, try that, the edited version would preserve the other values

1 Like

You can do

Object.Cframe * Vector3.new(10,0,0)
4 Likes

Thanks this was less complicated than I thought it was going to be

1 Like

Yea yours is a better method of doing it

1 Like

Just remember to capitalise the f. Otherwise you’ll get a ’Cframe is not a valid member of {instance}’ error.

4 Likes