How to keep a part in same relative position as parent part increases in size

I have a part weldconstrainted and parented to another like this (parent part is the grey ground piece)
image

When the parent changes in size on either the X or Y axis, how would I set the new position of the part to be in the same relative position as before the size change?

What I mean is, if the part was located close to the edge and then the parent’s size increased by 10 studs, how would I calculate the position so the part would remain close to the edge when the parent size has changed?

You can store the WorldCFrame of the attachments and refresh their alignment when the parent part’s size/position changes

1 Like

Oops, I forgot Attachments are an actual thing haha

I edited my post to provide slightly more detail. But if I did end up using Attachments, how would I do that exactly?

This should do the trick

local SizeChangingPart = workspace.RelativePartsSize.SizeChangingPart -- The part that changes size
local PositionChangingPart = workspace.RelativePartsSize.PositionChangingPart -- The part you want to remain relative based on the size of the first part

local OriginalSize = SizeChangingPart.Size
local OriginalPosition = PositionChangingPart.Position

SizeChangingPart:GetPropertyChangedSignal("Size"):Connect(function()
	PositionChangingPart.Position = OriginalPosition * (SizeChangingPart.Size / OriginalSize)
end)

Do note that this is relative in terms of true values so if you scale x2 the part will be much further away from the scaled part. If you want the actual distance away from the part to remain constant you can either use the solution officerpigbelly suggested or raycast normals.

1 Like