You should really be using TweenService for this as it is a much smoother way of rotating an object than the way you are trying to do it. TweenService gives you lots of control over how you want the tween to play, for example you can set how long you want the tween to take or how many times you want the tween to repeat.
First off we will need to define our variables. As TweenService is a service we need to get it through GetService()
and it is better practice to put this at the top of your script with the other variables that will be used throughout your script:
local TweenService = game:GetService("TweenService")
local Object = script.Parent -- The object you want to tween.
Secondly we will need to create our TweenInfo. The TweenInfo is used as the settings of the tween. Like for example you can set how long you want the tween to take to complete and how many times you want the tween to run:
local tweenInfo = TweenInfo.new(
5, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style in this case it is Linear
Enum.EasingDirection.Out, -- EasingDirection
-1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
false, -- Reverse?
0 -- Delay
)
Next will need to create the tween. You can do this by simply doing TweenService:Create()
. This takes 3 parameters, the first being the object that you want tweened, the second being the TweenInfo we created earlier and third being a dictionary of the properties you want tweened with the values you want them to be tween to:
local Tween = TweenService:Create(Object, tweenInfo, {Rotation = 360}) -- Creates the tween with the TweenInfo and what properties you want to change
Lastly before you test you need to tell the tween to play, this can be done by using Tween:Play()
. Alternatively you can use Tween:Pause()
to pause the tween and Tween:Cancel()
to cancel the tween.
Full script:
local TweenService = game:GetService("TweenService")
local Object = script.Parent -- The object you want to tween.
local tweenInfo = TweenInfo.new(
5, -- The time the tween takes to complete
Enum.EasingStyle.Linear, -- The tween style.
Enum.EasingDirection.Out, -- EasingDirection
-1, -- How many times you want the tween to repeat. If you make it less than 0 it will repeat forever.
false, -- Reverse?
0 -- Delay
)
local Tween = TweenService:Create(Object, tweenInfo, {Rotation = 360}) -- Creates the tween with the TweenInfo and what properties you want to change
Tween:Play() -- Plays the tween
If you edit the code above you should be able to make it work for what you are trying to do.
References: