What's the best way of rotating a part?

hello! im just trying to look for the best/performant way of continuously rotating a part 360 degrees.

i’ve seen people do it this way:

while true do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0) * CFrame.fromEulerAnglesXYZ(0, 00.1, 0) --mess around with these numbers if you want
wait()-- kind of the speed it moves/spins at but i recomend not putting it higher then one if you put nothing it will do 0.001                                             --^   

would this be the best way to go?


you could use task.wait() because wait() is deprecated


cool cool! tysm for ur response, ill try that :smiley:

Instead of that, I’d use CFrame.Angles:

script.Parent.CFrame * CFrame.Angles(0, math.rad(0.1), 0)

Keep in mind that rotations for CFrame.Angles are applied in a Z, Y, X order!


I’d recommend using physics instead of scripts


hey alex,
i tried math.rad a few times but unfortunately it doesnt seem to work.

i had it like u said

while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(0), math.rad(0.001), math.rad(0))

wdym by physics. like u mean constraints right? or am i missing something

Only put math.rad on the axis you’re rotating the part on:

script.Parent.CFrame * CFrame.Angles(0, math.rad(0.1), 0)
1 Like

Yeah I’d use hinge constraints (if I remember right)

ah thats really cool. its way smoother if u use math.rad as well. thank u so much man. thats exactly what i wanted. :slight_smile:

	while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, math.rad(5), 0)
1 Like

If you want the rotation to have physics and spin other objects, use Align-Position and Align-Orientation to keep the part in place while rotating it.

With this route you can use a basic script to keep it rotating

local part = script.Parent
local runService = game:GetService("RunService")

local attachment = Instance.new("Attachment",part)
local alignPosition = Instance.new("AlignPosition",part)
local alignOrientation = Instance.new("AlignOrientation",part)

alignPosition.RigidityEnabled = true
alignPosition.Attachment0 = attachment
alignPosition.Mode = 0 --one attachment enum

alignOrientation.RigidityEnabled = true
alignOrientation.Attachment0 = attachment
alignOrientation.Mode = 0 --one attachment enum

--Position where the part already is
alignPosition.Position = part.Position

--Rotate to how the part already is
alignOrientation.CFrame = part.CFrame

--Rotate forever
local connection = runService.Stepped:Connect(function()
	alignOrientation.CFrame *= CFrame.Angles(0,0.01,0)

--If the part will ever be destroyed, disconnect the connection to save resources

If you only want a visual effect
The easiest way to achieve the rotating effect without utilizing physics features is TweenService.
TweenService changes an Instance’s properties rapidly using a tween.

Example code:

local part = script.Parent
local tweenService = game:GetService("TweenService")

--Change these to your liking
local duration = 1 --Speed of the tween
local easingStyle = Enum.EasingStyle.Linear
local easingDirection = Enum.EasingDirection.In
local repeatCount = -1 --Infinitely tween
local reverses = false --Go back to original properties after tween

--Make the tween info
local tweenInfo = TweenInfo.new(duration,easingStyle,easingDirection,repeatCount,reverses)

--New Properties
local properties = {
	Orientation = Vector3.new(0,360,0) --Make it spin in a complete circle

--Make the initial tween
local tween = tweenService:Create(part,tweenInfo,properties)

--Play the tween

Can you rotate parts only this way or models will work to?

1 Like

models work too but u need a part and u set the models primary part to whatever part u made and weld all the parts in your model together. and make sure ONLY the primary part is anchored. nothing else.


1 Like

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