How to make a Motor turn smoothly

I am trying to make a gun rotate on a mount using a Motor.
The problem is that the motor seems to snap to increments instead of moving to the exact desired angle.
See the video below:
robloxapp-20200429-1357538.wmv (114.7 KB)
I couldn’t find any documentation on this behavior.

Here is my current code:

while true do
    wait()
    local t = time() * 0.1
    motor1:SetDesiredAngle(t)
end

I know I can decrease the max rotation speed of the motor, but that doesn’t fix the angle snapping effect.

If I print out the CurrentAngle of the motor in the loop, I get this:

0 (x4)
0.037916667759418 (x9)
0.075833335518837 (x12)
0.11583334207535 (x13)
0.15916667878628 (x13)
0.20250001549721 (x14)
0.24875001609325 (x14)
0.2954166829586 (x15)
0.34541669487953 (x15)
0.39541667699814 (x8)

Clearly it is snapping the motor to specific angles. (The increment is about 7/150.)

Even if I remove the loop and set the angles directly, the actual angle snaps to unusual increments. For example:

motor1:SetDesiredAngle(1.01)
wait(0.5)
print(motor1.CurrentAngle)

motor1:SetDesiredAngle(1.03)
wait(0.5)
print(motor1.CurrentAngle)

motor1:SetDesiredAngle(1.07)
wait(0.5)
print(motor1.CurrentAngle)

motor1:SetDesiredAngle(1.25)
wait(0.5)
print(motor1.CurrentAngle)

This prints

1.0099999904633
1.0099999904633
1.0099999904633
1.25

Does anyone know of a way around this? I would like to avoid updating the joint on every frame if possible. I basically need some sort of motorized ball-socket constraint, but one doesn’t seem to exist.

You should avoid using while true do and wait() in your code: Avoiding wait() and why

Also, is this script a Script or a LocalScript?

I’m only using wait() in an infinite while loop for testing.
This is in a server-side script.

Try using Heartbeat and see if there’s any difference.

Edit: You actually shouldn’t be calling SetDesiredAngle that frequently, try calling with 180 then to 360 every 5 seconds or so.

I know it will move smoothly at large angles like 180 or 360 degrees. But I need it to move across very small angles (like 0.1 degrees).

Try setting CurrentAngle directly, and see if it works. I think SetDesiredAngle is only used for smooth movements, but doing them every wait() seems a bit inefficient.

Even if I remove the loop completely, it doesn’t go to the correct angle.
(I’ll update the post with this.)

And setting the CurrentAngle directly does not work.