How to make sure a part's orientation stays at (0,0,0)

I would like to have a script that allows a part’s orientation to always reset back to 0 if the part does change orientation

I have tried to look for other resources but all resulting in failure (no errors whatsoever)

Try this:


while wait() do
    part.CFrame = CFrame.new(part.Position)
end

As long as the script is running, this script will make the part’s orientation stay at (0,0,0)

That’s for position. Apart from it not being what OP asked, it is actually incorrect. For Orientation, use CFrame.Angles.

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
	part.CFrame = CFrame.Angles(0, 0, 0)
end)

-- Or you can obviously use a while loop...
while task.wait() do
	part.CFrame = CFrame.Angles(0, 0, 0)
end

Actually, I think I messed up.

this is the reason why you must sleep well

You should use AlignOrientation with RigidityEnabled for this.

local Center = Instance.new("Attachment")
Center.Parent = Part

local AlignOrient = Instance.new("AlignOrientation")
AlignOrient.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignOrient.Attachment0 = Center
AlignOrient.RigidityEnabled = true
AlignOrient.CFrame = CFrame.new()
AlignOrient.Parent = Part

Hope this helped!

1 Like

yeah this seems like a better answer because i dont even know what the OP means

time to leave

while task.wait() do
    part.Orientation = Vector3.new(0,0,0)
end

What xDeltaXen said worked as well, though this should also work just fine.

You could have at least connected it to the Heartbeat event

1 Like

This doesn’t work for some reason, I also tried it on a regular part and it doesn’t set the orientation

1 Like

I tried this too but nothing happened to the part

1 Like

Not sure if I am doing something wrong, I am using a normal part and changing the orientation manually to test it… But doesn’t work.

1 Like

This also won’t do anything to the part

1 Like
part:GetPropertyChangedSignal("Orientation"):Connect(function()
part.Orientation = Vector3.new()
end)

I’m pretty sure it’s the same thing, it loops infinitely, just like runservice

I’m surprised to see how many people use infinite loops for everything…
Infinite loops take extremely high ressources overall, you should avoid to use them for everything while there are surely some other solutions to do things properly in an optimized way.

Solution 1

local Part = script.parent --Change to your part localization
script.Parent:GetPropertyChangedSignal("Orientation"):Connect(function()
	Part.CFrame = Part.CFrame * CFrame.Angles(0, 0, 0)
end)

Solution 2

local Part = script.parent --Change to your part localization
local Gyro = Instance.new("BodyGyro")

Gyro.Parent = Part
Gyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

Solution 3

2 Likes

It’s not a good practice as they are not synced up with physics and that will create conflicts with them

Take a look at this example
Red brick sets the orientation to 0,0,0 every loop cycle
Green brick uses AlignOrientation with RigidityEnabled

1 Like

Shockingly to everyone, xDeltaXen is actually right on this. The code he found and shared resets the rotation of the part but keeps the position. Your code resets both rotation and position.

1 Like

Sorry, apparently a gravity script I had was interfering with the orientation, otherwise… These all work greatly

1 Like

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