Tweening 360 Degrees

I’m clueless on how to tween a model 360 degrees. Currently It’s tweening 180 degrees and just restarting the tween when it reaches 180 to re-create a spinning effect, but that’s not what I need.
Here is the script I’m using.

local ts = game:GetService("TweenService")
local model = workspace.Model.PrimaryPart


local info = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out,-1)

local properties = {CFrame = model.CFrame * CFrame.Angles(0,math.rad(180),0)}

local tween = ts:Create(model,info,properties)

tween:Play()
wait(5)
tween:Play()

Simply change 180 to 360 in this line.

The issue is I believe TweenService looks to take the shortest path which in this case would be not rotating at all.

1 Like

Ah, my bad. I didn’t properly read the code.

In that case, you could have a variable such as local Rotation = 0.
Then in your code, just add 360 to Rotation every time you want to tween it.

E.g.

Rotation = Rotation + 360
local properties = {CFrame = model.CFrame * CFrame.Angles(0,math.rad(Rotation),0)}

Edit: ahah I did it again. Let me make a new answer, I guess I’m just a bit tired and fuzzy heh.

Since you have an easing style of Linear you could tween it every 90 degrees and it shouldn’t cause too many issues.

Found this post that answer provides some useful information: Alarm system with TweenService

If TS takes the shortest path to restart the tween, instead of 360, use 360.1 or 361. That might help.
(Sorry I didn’t mean to reply you, xZylter)

Except for this to work it has to a minimum 3 separate tween goals. Since if you did 361 that would default to 1 degree. It’s a really annoying this to solve. :confused:

1 Like

I would’ve tweened a NumberValue instead, then updating the part’s CFrame when the NumberValue changes due to the tween.

Assuming you have a NumberValue parented to your script, the code could be something like this:

local TweenService = game:GetService("TweenService")

local NumberValue = script:WaitForChild("Value")

local Rotation = 0

function Rotate360Degrees()

Rotation = Rotation + 360

TweenService:Create(NumberValue, TweenInfo.new(5), {Value = Rotation}):Play()

end

local LastRotation = 0

NumberValue:GetPropertyChangedSignal("Value"):Connect(function()

Part.CFrame = Part.CFrame * CFrame.Angles(0, math.rad(-LastRotation + NumberValue.Value), 0) -- This negates the previous rotation applied to the part

LastRotation = NumberValue.Value

end)

Rotate360Degrees()

I don’t know what you’re trying to do this for, but I’d definitely use an animation instead if it was for the character to spin.

I would rotate it 120 degrees 3 times

1 Like

Question, do you want it to spin without stopping? or just do a 360 once?

Edit: replied to wrong person

I wanted the tween to rotate 360 degrees at once. That didn’t work out because of the tween taking the path of the least resistance. Instead I rotated it 3 times 120 degrees and it worked. I think and hope there is a better way of doing this so, I’m going to leave this post open for future replies and solutions.

1 Like

I did give you a solution to achieve what you described.

1 Like

What if it wasn’t linear tho? I’m trying to make a game logo rotate with easing style

Late response, sorry, but I found a solution for the game logo situation.

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local function RotateGui()
	for i = 1, 360, 3 do
		i = TweenService:GetValue((i/360), Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut)
		script.Parent.Rotation = i * 360
		RunService.RenderStepped:Wait()
	end
end

while true do 
	RotateGui()
end

Change the Enum.EasingStyle and EasingDirection to whatever you’d like, and to make it faster, increase the number 3 on line 4 (be sure that the number goes into 360 though)

1 Like