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 --^
end
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)
end)
--If the part will ever be destroyed, disconnect the connection to save resources
part.Destroying:Connect(function()
connection:Disconnect()
end)
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
tween:Play()
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.