How to create a rotating object using TweenService?

Hello. I am a Roblox Builder and modeller and have barely any scripting experience so I am looking for some help with an object I would like to rotate.

I am looking to create a teleport “portal” which rotates to attract players eyes using Tween Service or C-frame (not sure what the difference is even).

I have objects in my game that float up and down, but I am looking for this one to rotate in a loop and if possible float up and down at the same time.

I attached an image of the rotational direction i’d like - any help is greatly appreciated!

2 Likes

Would using the AngularVelocity Constraint help you do you think?

If that doesn’t work then you could try the following server script code. Its worked for me before although it’s probably really jank.

local part = -- put the path to your part here

while task.wait(cooldown) do -- cooldown decides rate of spin, play around with it to get a value you like
	part.CFrame *= CFrame.Angles(0, increment, 0) -- the increment decides the degree of spin per cooldown
end

setting cooldown to 0.05 and increment to 0.5 in the above code gives this:

2 Likes

this is a script that rotates a part on the Y axis while making it float on the y axis forever

local TweenService = game:GetService("TweenService")

local Part = workspace.Part -- The Part You Will Rotate

TweenService:Create(Part,
	TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In,-1,false),
	{ Rotation = Vector3.new(0,180,0) }
):Play() -- the rotation tween

TweenService:Create(Part,
	TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In,-1,true),
	{ Position = Part.Position + Vector3.new(0,10,0) }
):Play() -- the float script

replace the Part variable to the instance that you want to rotate and if you want to make it rotate faster change the first argument in the TweenInfo.new
the differance between TweenService and CFrame is that tween service can be used to change any value smoothy like transparency/reflection/position/rotation/cframe
while cframe is used mostly for math like if you want a part to look towards a player you would use CFrame etc

if you want to change how the part rotates/moves change the Enum.EasingStyle.Linear to any other value like Enum.EasingStyle.Sine | Enum.EasingStyle.Bounce etc

1 Like

you can make a rotating animation and use that

1 Like

Try this

local Part = -- Part Path
local TweenService = game:GetService("TweenService")
local TI = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, false)
local TI2 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1, true)


TweenService:Create(Part, TI, {Orientation = Vector3.new(0,360,0)}):Play()

TweenService:Create(Part, TI2, {Position = Part.Position+Vector3.new(0,2,0)}):Play()
 

Put it in a server script inside the Part, or better, put it in a local script in StarterPlayer, StarterCharacterScripts, to avoid choppiness.

This works great and thank you so much for the explanation of all the different aspects. Really helps when I’m trying to gather a basic understanding!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.