How to rotate infinitely using tweens?

Howdy! I’m trying to make a lighthouse, but somehow, the part just rotates back and forth after rotating 360 degrees as seen in the video:


Here’s the code:
–rotation
local RON = {
Orientation = Vector3.new(0,360,0)
}

8 Likes

Try this:
Change the part to the main part

local RON = {
CFrame = part.CFrame * CFrame.Angles(0,math.rad(1),0)
}

1 Like

It didn’t work, unfortunately.

What happend with the lighthouse with that code?

I recommend using checkpoints, like tween it to 90 degree angle, then 180, then 270, then 360. After you reach 360 degrees, the orientation is at a max (I think). So instead of tweening, when you reach 360 degrees (or 359 if 360 does not work) simply set the orientation/rotation back to 0, then loop the normal tweening again.

Wdym, as seen in the video, the light is rotating back and forth after reach 360 degrees

I’m no geek at programming but I do know how to tween.

Try this perhaps:

local ts = game:GetService("TweenService") --TweenService
local object = --Path to what object you're tweening
local info = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, false, 0) -- -1 is for repeat count which will be infinite, false is for bool reverses which means it will not go backwards
local goals = {Orientation = Vector3.new(0, 360, 0)} --Rotating it 360 degrees will make it go back to the original starting point, and with an infinite repeat count, it will go forever.
local tween = ts:Create(p, info, goals)
tween:Play()

Tested this in studio on a part and it does rotate forever in one direction. Hope this works!

15 Likes

Alternatively, you could use a CylindricalConstraint to achieve a similar result without scripting

1 Like

There’s an easy way to indefinetly repeat a tween, and that’s turning false the reverse propierty in TweenInfo and putting -1 in the repeat propierty

local Part = script.Parent
local TweenService = game:GetService("TweenService")

local TweenInfo1 = TweenInfo.new(
	1.5,							-- Tween Length
	Enum.EasingStyle.Linear,		-- Easing Style (Animation Style)
	Enum.EasingDirection.InOut,		-- Easing Direction
	-1,								-- Times repeated (0 is play once, -1 is infinite loop)
	false,							-- Reverse
	0								-- Delay
)

local TweenGoals1 = {
	Orientation = Part.Orientation + Vector3.new(0,360,0);
}

local Tween1 = TweenService:Create(Part,TweenInfo1,TweenGoals1)

Tween1:Play()

Edit: I know this has been solved before but I wanted to post a more expanded and comprehensible script

8 Likes