I have a part weldconstrainted and parented to another like this (parent part is the grey ground piece)
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?
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.