How do I make a smooth spinning effect?

So my goal here is to make a part spin. I want a very nice smooth effect. The reason being, I want to make a knife and I want to make it spin towards the target when thrown. If anyone can help me with that, I would appreciate it very much.

18 Likes
while true do
    script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(rorationsXperSec,rotationsYperSec,rotationsZperSec)
end

This might work, I found it in a tutorial on youtube

19 Likes

Here’s a script I use.

6 Likes

If you use physics I recommend to use BodyGyro, if you use CFrame then change their angles.

local X, Y, Z = .1, 0, 0
while wait() do
     Part.CFrame = Part.CFrame*CFrame.Angles(X, Y, Z)
end
8 Likes
local RunService = game:GetService("RunService")

RunService:BindToRenderStep("Rotation"--[[Must have a unique name, if you  have multiple parts make sure to change it]], 199, function()
   if Part.Parent then -- Check if the part exists
      Part.CFrame = Part.CFrame * CFrame.Angles(math.rad(0.1), 0, 0)
   else
      RunService:UnbindFromRenderStep("Rotation") -- Stop the loop from running
   end
end)
8 Likes

You can use renderstepped on the client or heartbeat on the server. May be overkill but atleast its smooth.
Heartbeat: RunService | Documentation - Roblox Creator Hub
Renderstepped: RunService | Documentation - Roblox Creator Hub

4 Likes
local RunService = game:GetService("RunService")
local Angle = math.deg(1)
RunService:BindToRenderStep("Rotation"--[[Must have a unique name, if you  have multiple parts make sure to change it]], 199, function(dt)
   if Part.Parent then -- Check if the part exists
      Part.CFrame = Part.CFrame * CFrame.Angles(Angle * dt, 0, 0)
   else
      RunService:UnbindFromRenderStep("Rotation") -- Stop the loop from running
   end
end)

I’ve multiplied the angle by the length of the frame, so the spinning speed is consistent for people running with different frame rates

18 Likes

That’s nice too! I personally don’t care about consistency for things like this as it doesn’t really have any advantage

3 Likes

This is a misuse of repeat loops and falls under the same category of misusing the condition for loops, such as placing wait as the condition for a while loop. Use a while loop instead with true as the condition to achieve a proper non-terminating loop.

4 Likes

Just thought I’d mention that while the answer you’ve marked as correct does work, it will not be smooth for a lot of people, as using wait() in a loop will not synchronise with the clients frame rate. You shouldn’t really be using while wait() do anywhere on your code

8 Likes

I would add a wait() or while wait() do since no wait in a while loop is gonna break your game.

2 Likes

Is there an easier way to do this without using a function? I want to continue the script afterwards but the “end” part is not allowing me to.

1 Like

you can put it in a runservice connection like heartbeat,stepped,renderstepped only renderstepped if its client, or you can use things like spawn or coroutines to make it so it wont stop the script thread and make a seperate thread.

1 Like

Use tweening TweenService | Roblox Creator Documentation

1 Like

instead of using a while true loop, you should use a while wait() loop. it’s easier than putting wait() at the end.

1 Like