Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How exactly would I change the rotation of a part?

So, in a script I'm making I want a part to have a constant rotation of (0, 0, 0). Unfortunately, I don't know how to change the rotation of an object through script. The current script I have is this:

function changed(Rotation)
	if script.Parent.CFrame ~= script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0) then -- if rotation is not (0, 0, 0) then
		script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0) -- make rotation (0, 0, 0)
	end
end

script.Parent.Changed:connect(changed) -- script.Parent is a part

So, I need a statement that will correctly change an object's rotation through script, without the math.pi mumbo jumbo (unless that's the only way to do it).

1 answer

The easiest way to make an object have no rotation is to use this nifty like hack:

script.Parent.CFrame = CFrame.new(script.Parent.Position)

Your if statement is always true, by the way, because CFrame.Angles() applies a Rotation, it doesn't set the Rotation. In order to actually get the current Rotation of a part, you're going to have to look at its Rotation Vector3, or do math to the results of The components method of CFrame.

4 comments

0

Why does changing the rotation have to be so complex in Lua? It should just be the same as position...

0

It's not complex at all, actually. The problem with setting Position and Rotation directly is that ROBLOX will then shunt the Parts upwards until there are no collisions. This can only be circumvented by using CFrame.

0

So, how would I get a value out of rotation, such as putting a part's rotation into a Vector3Value?

0

Vector3Value.Value = Part.Rotation --Rotation as a property IS a Vector3.

This discussion is preserved as it was. New answers, comments, and votes are closed.