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