What is the best script for rotating parts

I am made a gear Model and I am trying to write a script for it to rotate with the angle 45 degrees. But there was a problem in my script, I can’t control the rotation speed :frowning:
I already made the rotateAmount inside the script but if I insert any numbers except for 0, I can’t control the rotation speed and the gear would go crazy and spin with some weird angles and speed.

The rotateAmount with other numbers:

TherotateAmount with 0:

Script

local model = script.Parent
local rad = math.rad
local rotateAmount = 1 -- In degrees


while true do
	wait(0.002)
	local newCFrame = model.PrimaryPart.CFrame * CFrame.Angles(45, rad(rotateAmount),0)
	model:SetPrimaryPartCFrame(newCFrame)
end 

Is there any other ways to fix this or there are some better scripts for this? Please help :smiley:

The 45 is causing the rotation along the x axis not the one inside the y axis. Modify the 45 to be the rotation amount instead.

Also there is a door rotating example on this article which should be the best option as it uses delta time making it frame independent and work well even on computers with low fps

local door = game.Workspace.Door
 
game:GetService("RunService").Heartbeat:connect(function(dt)
	door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0)
end)
2 Likes

TYYYY it literally worked :smiley: Tysm