How to optimize this

I’m working on a game that has a large, rotating cube. The cube rotates using TweenService. I originally had all of the parts of the cube (30-90 parts; never counted) separated. I then used the well known weld plugin. I clicked the “weld all” option while selecting all of my parts. It inserted a weld into each. I made one of the parts the “root” part of the model. I then connected the script (run on the client to prevent glitchy tweens) to the root part. In theory, this should rotate the entire model. However, it unexpectedly only rotated the the root part. (yes the other parts had anchored set to False) The other parts were suspended in the air, so the welds were clearly working, but the tween wasn’t affecting the other parts… I then removed the welds and created 2 unions instead. I used WeldConstraints this time. I welded the 3 parts (inner shell, outer shell, and primary). Once again, only the primary rotated.

My solution? Create separate tweens for each of them. This method works, however, I realize this has a negative impact on performance. Unions are notorious for causing lag and multiple tweens can’t be the most efficient way to handle this. How can I better do this?

5 Likes

Can you show the line of code you use to rotate it?

I assume you’re using CFrame not rotation right? (Rotation doesn’t work the way you intend with welds.)

2 Likes

Can you use a motor?

You could attach the PrimaryPart of your cube to an Anchored part, then spin the cube with a motor that is inside the Anchored Part.

1 Like

Also, you can implement your own tween with Model:PiviotTo(cframe). Just use CFrameStart:Lerp(CFrameEnd, percentage) to get a percentage and update every render stepped.

1 Like

Sorry, I meant to include the script


local TweenService = game:GetService("TweenService")
local part = game.Workspace:WaitForChild("Cube"):WaitForChild("Primary")
local inner = game.Workspace:WaitForChild("Cube"):WaitForChild("Inner")
local outer = game.Workspace:WaitForChild("Cube"):WaitForChild("Outer")

local Info = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, math.huge)
local Goals = {Orientation = Vector3.new(0, 360, 0)}

local tween = TweenService:Create(part,Info,Goals)
local tween2 = TweenService:Create(inner,Info,Goals)
local tween3 = TweenService:Create(outer,Info,Goals)

wait(3)

tween:Play()
tween2:Play()
tween3:Play()

I’ve never tried that method before

I think the problem is that you need to use CFrame instead of Orientation. Welds are set up so that they can be adjusted relatively using Position and Rotation and moved together using CFrame.

Try using the same code but use a CFrame target. (Use part.CFrame * CFrame.Angles(0, 0, math.rad(360) as the goal for each part.)

1 Like

Got a error: Unable to cast to dictionary

You need to format the table like: {CFrame = part.CFrame * CFrame.Angles(0, 0, math.rad(360)}