Tweening Assistance

What I’m Trying To Achieve
I have 3 cubes scrip[ted to spin on 2 90-degree axi.
When I run the script, the first loop through works fine.
They spin the way I want to via Tweening and then reverse correctly as well.

The Issue
When it gets to the second loop and so forth, the cubes start spiraling out of control and randomly heading in directions unintended.

As you can see on this gif, the first time they spin is the correct way. The second time is random.
https://gyazo.com/93c256d25a6868a6bb3e688d5a3479b1

My Code
Maybe there is something about the math I’m unaware of?

local tweenService = game:GetService("TweenService")

local cubes = game.Workspace.NewObby.SpawnArea["Floating Cubes"]:GetChildren() 

local tweenInfo = TweenInfo.new(
	5, -- time to complete the tween
	Enum.EasingStyle.Linear, -- easing style of the tween
	Enum.EasingDirection.InOut, -- direction of the easing style (in this case it's both)
	-1, -- number of times to repeat (-1 means infinite)
	true, -- reverses the animation when it repeats (true means yes)
	0) -- delay before starting the tween

for _, cube in ipairs(cubes) do
	tweenService:Create(cube, tweenInfo, {CFrame = cube.CFrame * CFrame.Angles(90, math.rad(90), 0)})
	:Play()
end

This is probably due to the tween getting the cubes new cframe (position and orientation) every time. You should consider having a Starting cframe and Goal cframe and then tween between the 2.

1 Like

I think i understand what you mean but not fully.
Could you elaborate on how it would be done?

Could not replicate problem!
Sadly, I attempted to replicate your problem and couldent!
Check the part’s and make sure that “massless” is off.
This could be causing problems although unlikely.
(my tests we’re done using server-script)
image

I have the script in a folder within SSS.

Make sure your cubes are anchored.

2 Likes

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