Tweening Orientation on a Part doesn't affect the Part's Welds?

I’m trying to tween a part’s Orientation in order to rotate in Local Space instead of World Space (if I wanted to rotate a part with World Space, I would use CFrame instead).

The thing is, other parts attached to the original part via welds aren’t rotated with it. CFrame does the trick, but I’m trying to use Local Space instead of World Space to rotate the part.

Using CFrame wouldn’t work in my system, where I serialize part properties into a dictionary and take values from there to tween.


local module = {}

local TweenService = game:GetService("TweenService")

local savedParts = {}
local partProps = { "A list of properties that I wanted to save." }

function module.serializePart(part)

  local p = {}
  for i, property in pairs(partProps) do
    p[property] = part[property]
  end

  savedParts[part] = p
end

function module.rotatePart(part)
    local props = editParts[part]

  -- This is where I would take the part's current Orientation and
  -- change it via TweenService.

  TweenService:Create(part, tweenInfo, properties):Play()

end

return module

What should I do to make welded parts move with the tween?

You could setup a tween for each part attached to the object, if it’s inside a model you can do a for loop on the children, create a tween, place that inside a table, then after the for loop is completed, go though the second table and play each tween.

This is simple to fix, turn on the constraints, use the weld constraint, weld the part to the other part and it’ll rotate with it.

Changing orientation rotates the part on world space and changing CFrame usually rotates it in local space. CFrame:ToWorldSpace(cf) takes a local offset and calculates the offsetted CFrame in world space. Because the offset s local, it rotates or moves in local space. It is the same as CFrame*cf.

You can use CFrames for rotating in world space, too. You just need to have the rotation first and the CFrame to rotate after it in the calculation. However, in this situation the rotation should probably be done this way.

local targetOrientation = -- the orientation you want to tween to

local radTargetOri = targetOrientation*(math.pi/180)
local targetCf = CFrame.FromOrientation(radTargetOri.X, radTargetOri.Y, radTargetOri.Z)+part.Position

local properties = {CFrame = targetCf}

Edit: I didn’t realise that I need to give numbers to fromOrientation, not a Vector3. I have fixed the code now.

1 Like