Just curious why this runtime parenting isn't working

Code:

local part = game.Workspace.Part
local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2

part1.Parent = part
part2.Parent = part

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear)
local tweenGoal = {
	CFrame = part.CFrame * CFrame.Angles(0, 90, 0)
}

local tween = TweenService:Create(part, tweenInfo, tweenGoal)

tween:Play()

Problem:

1 Like

Why did you make part 1 and part 2’s parent to Part?

It did work the Parent of the Part1 and Part2 were set to Part.

I don’t understand your question. It’s the whole point of the test.

What? Thats what im doing…

I think you’re a little confused on what specifically isn’t working here. Your parenting is working and judging by the video, I assume your expectation is that the other two parts rotate around with the larger part when parented. That’s not how it works.

Studio tools will account for all descendant BaseParts and update their orientations in object space which is why when you use the Studio rotation tool on the bigger block, the smaller ones rotate as well. In a runtime environment, to achieve this behaviour you need to use welds. The two parts must be unanchored and welded to the bigger block. You can use WeldConstraints for this.

2 Likes

But the code is working so I don’t get your problem? The parent property affect where the part is placed, and the Part1 and Part2 parents are set to Part.

if you want it to work just tie it in with the code I gave you to your previous question like this:

local TweenService = game:GetService("TweenService")

local part = game.Workspace.Part
local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2
local part1Offset = part.CFrame:Inverse() * part1.CFrame
local part2Offset = part.CFrame:Inverse() * part2.CFrame
local connection

connection = part:GetPropertyChangedSignal("CFrame"):Connect(function()
    part1.CFrame = part.CFrame * part1Offset
    part2.CFrame = part.CFrame * part2Offset
end)

local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear)
local tweenGoal = {
	CFrame = part.CFrame * CFrame.Angles(0, 90, 0)
}

local tween = TweenService:Create(part, tweenInfo, tweenGoal)

tween:Play()
tween.Completed:Wait()
connection:Disconnect()
1 Like

OK. So it’s expected to not work in runtime? When rotating with studio tools a different logic kicks in? If thats the case, I mark your answer as solution and case closed. Thank you.

Thank you! I was just curios why this approach is also not working :slight_smile:

1 Like

Everything works, it’s just that you might be unaware about the relation of parts to their parents and why this behaviour occurs.

Parts not rotating with their parents is the default and expected behaviour. To provide a comfortable user experience and not have to rotate mass amounts of parts, the Studio rotate tool will account for descendant BaseParts and rotate them, as well as a selected part, together as if they were one assembly.

In a runtime environment the behaviour of the Studio rotate tool is not in effect so you must find a way to connect these two parts. Enter: joints, that connect two parts together. And if not that, then you require extra code that will explicitly moves the two smaller blocks with the larger one in object space.

1 Like