Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Is tweenservice not rotating?

local TweenService = game:GetService("TweenService")
local PartProperties = {CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(360),0) }
local TweenInfov = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Linear,--EasingStyle
	Enum.EasingDirection.Out,--Easing direction
	9999999999,--times to repeat
	false,--goes in reverse
	0--Idk what this is
)

local Tween = TweenService:Create(script.Parent,TweenInfov,PartProperties)
Tween:Play()

For some reason, instead of rotating the part, it moves to a seemingly random position, that is not 0,360,0 but is always the same.

1 answer

✓ Accepted answer

Unfortunately you can't achieve rotation with TweenService easily. Tweens will always choose shortest "path" to their goal. Half turn is the best you can get, but you also have no control over the direction of spin.

To solve this you need to do some shenanigans. I, for example, create three tweens, each making one third of a turn. Two tweens are not enough, and usually result in part "swinging" forward and back. This way you "force" tween to make a full 360 degree turn.

local TweenService = game:GetService("TweenService")
local PartProperties1 = {CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(120),0) }
local PartProperties2 = {CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(240),0) }
local PartProperties3 = {CFrame = script.Parent.CFrame}

local TweenInfov = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Linear,--EasingStyle
    Enum.EasingDirection.Out,--Easing direction
    0, --put -1 for infinite repeats, but in this case we do not need this
    false, --true means the tween will go back once finished
    0 -- delay timer in seconds before tween plays
)

local Tween1 = TweenService:Create(script.Parent,TweenInfov,PartProperties1)
local Tween2 = TweenService:Create(script.Parent,TweenInfov,PartProperties2)
local Tween3 = TweenService:Create(script.Parent,TweenInfov,PartProperties3)

Tween1.Completed:Connect(function() Tween2:Play() end)
Tween2.Completed:Connect(function() Tween3:Play() end)
Tween3.Completed:Connect(function() Tween1:Play() end)

Tween1:Play()

Swap tweens around, to change direction of the spin. I hope this helps!

p.s. As a side note, to stop the spin you will need to disconnect those connections. For example:

local con1 = Tween1.Completed:Connect(function() Tween2:Play() end)
local con2 = Tween2.Completed:Connect(function() Tween3:Play() end)
local con3 = Tween3.Completed:Connect(function() Tween1:Play() end)

Tween1:Play()

wait(10) - let it spin

con1:Disconnect()
con2:Disconnect()
con3:Disconnect()

Edit: Added missing brackets

1 comment

0

Thank you, my game is one step closer to finished ;) , also, to anyone else reading this, add wait(0.2) at the start if you plan on using the script on a part from replicated storage, else it will glide to the position of the original part

This discussion is preserved as it was. New answers, comments, and votes are closed.