What is the best way to tween part around its own axis?

Hello
I would like to tween rotate a sphere, having initial rotation = (0,0,25) around its local Y axis indefinitely.
Is there a way to do this using a goal, which I can set in advance?
Or I will need to tween some numerical value and change the sphere cframe manually when “changed” event of the numerical value is triggerred? (which I guess will be much more unefficient…)

Thanks in advance

2 Likes

Try this:
local TweenService = game:GetService(“TweenService”)
local Workspace = game:GetService(“Workspace”)

local rotationValue = Instance.new(“NumberValue”)
rotationValue.Name = “RotationValue”
rotationValue.Value = 0
rotationValue.Parent = Workspace

local rotationGoal = {}
rotationGoal.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(0, math.rad(25), 0)

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge, true, 0)

local rotationTween = TweenService:Create(rotationValue, tweenInfo, rotationGoal)

rotationTween:Play()

rotationTween.Completed:Connect(function()
rotationValue.Value = 0
rotationTween:Play()
end)

2 Likes

not sure what you are doing here?
you are tweening a number value and you set a CFrame as goal?
is this generated with ChatGPT?

I watched a tutorial a while ago on advanced tweening so idk it’s wierd but it should work

do you need for it to be a tween or can it be in a loop?

If something is spinning at a linear speed forever on one axis I would suggest using RimServoce.RenderStepped (client) or HeartBeat (Server).

Option 1 (Recommended):

--[[ Local Script ]]--
local RunService = game:GetService("RunService")
local part = game.Workspace.Part
local speed = 5

RunService.RenderStepped:Connect(function(dt)
	part.CFrame *= CFrame.Angles(0, speed * dt, 0)
end)

Option 2:

--[[ Server Script ]]--
local RunService = game:GetService("RunService")
local part = game.Workspace.Part
local speed = 5

RunService.HeartBeat:Connect(function(dt)
	part.CFrame *= CFrame.Angles(0, speed * dt, 0)
end)