How to change only the X axis of a part?

Hello, I have this script that tweens my door. I want it to do some cool spinning action so I included it spinning on the X axis.

EVERYTHING WORKS AMAZING… but for some reason roblox REFUSES to change the X axis even though I am telling it to in the code.

Here’s my code:

local ts = game:GetService("TweenService")
local OpenPos = CFrame.new(Vector3.new(-107.743, 42.735, -43.132)) * CFrame.Angles(math.rad(35), math.rad(90), 0)
local OpenTween = ts:Create(Door, TweenInfo.new(2, Enum.EasingStyle.Linear), {CFrame = OpenPos})
OpenTween:Play()

Video of the door tweening and of the properties not changing the X axis


image
X is NEVER BEING CHANGED. and for some reason its instead treating X axis. like it’
s Z axis.

1 Like

This is not possible. X is readonly. You can’t change the X value of any property in roblox. Orientation.X, Position.X, Anything. For example:

part.Position.X += 5 -- wrong way
part.Position += Vector3.new(5, 0, 0) -- right way

Whenever you want to change a singular value, make sure to incorporate this method,

Also, you’re trying to multiply a Vector3 with a CFrame, that won’t work. Use CFrame.new(Vector3.new()) parameter. (MY BAD, I didn’t see that other parentheses, lol)

1 Like

I’m not sure that I understand what you’re saying. Why would X be read only but roblox allows me to change all the other cordinates? As you saw from the video of the properties being changes, roblox was letting me change the orientation. It was just treating X like it was Z. And when you say

Are you talking about for orientation or position?

1 Like

I’m talking about both.

That’s just the way it is. Position is a read and write property, Position.X is read only. You can change X by changing Position. And you have to do it that way.

When you say it was letting you change the other ones, that’s just not correct. You must be doing your calculations wrong. You should check if the position you are setting it to isn’t ALREADY what it is.

I’m never changing just the X value in my code though. If you look at my code I am using the full Vector3 and the full orientation

local OpenPos = CFrame.new(Vector3.new(-107.743, 42.735, -43.132)) * CFrame.Angles(math.rad(35), math.rad(90), 0)

See how I’m said CFrame.Angles() and entered all 3 required values after multiplying it? I’m never trying to say Position.X = 5.

Yes, but BEFORE you tween the part, is it’s X value -107.743? What you’re trying to set it as? It seems as if the Position property IS changing.

the starting orientation is
0, 90, 0

You’re trying to change the orientation, not the position?

I am trying to change both Orientation and Position as I want the vault door to spin but also slide into the correct spot.

Why not set the Position, and the orientation separately in the tween?

I have parts welded to this part and the only way to make those welded parts follow the part is by using CFrame. If you didn’t know, tweening the Position or Orientation ignores welded parts. It’s required to use CFrame.

TweenService will choose the path of least resistance to get the desired orientation and position, which can mean irregular rotations (like going in the opposite direction, skipping an axis, etc). This is because of how rotation matrixes work.

Make a pole that is the pivot point of the door, weld everything to it. Rotate it by 90 degrees with your tween.

If you’re doing something fancy, split the tween up and use Linear. Also, don’t make a CFrame with added rotations with .Angles, just find the CFrame in studio fire if its a static part of the world and give it that by snagging it with the command bar.

Alternatively, given I now see (I didn’t see this part) it’s changing the Z axis, maybe use another constructor like .FromEulerAnglesYXZ

I’m not too aware of the other functions of CFrame. can you show examples of how to write it?

Its the same thing just applied in a different order to get the desired rotation.

Try using CFrame.fromAxisAngle().

CFrame | Roblox Creator Documentation

2 Likes

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