You would want to use a formula to find the difference between the first size and the second size and then size it proportionately. TweenService isn’t really relevant in our case unless you want to create a smooth size effect. It’s mostly math and vector knowledge.
local initSize = Vector3.new(2,5,1.5) -- this would be any Vector3
local currentSize = Vector3.new(1,11.2,1) -- let's say 4.5 is the goal size but we only have the Y axis, this would be the new size
local offset = currentSize.Y / initSize.Y -- this will be how much bigger or smaller one of the axes will be
local x = initSize.X * offset
local y = currentSize.Y
local z = initSize.Z * offset
local scaledSize = Vector3.new(x,y,z)
workspace.ScaledPart.Size = scaledSize
This should scale up the part proportionately.
Now that’s only one part, what if we have more than one part? For the second part, we have to find the relative position from one part to the other. Thankfully, Roblox allows us to do this easily with CFrames.
To make it easier, let’s create a function to organize our code into functions.
local function getOffsetSize(initVector, offset) -- requires the part's size and the offset (new) size
local x = initVector.X * offset
local y = initVector.Y * offset
local z = initVector.Z * offset
return Vector3.new(x,y,z)
end
local function getOffset(initYAxis, goal) -- requires our initial Y axis and our goal axis
return goal / initYAxis
end
local function getOffsetPosition(primaryPartCFrame, part, offset) -- requires the models' primary part CFrame and our target part's cframe as well as the offset from the above function
local relativeVector = primaryPartCFrame:PointToObjectSpace(part.Position)
print(relativeVector)
local x = relativeVector.X * offset
local y = relativeVector.Y * offset
local z = relativeVector.Z * offset
local relativeVector = Vector3.new(x,y,z)
return primaryPartCFrame:PointToWorldSpace(relativeVector)
end
Finally, let’s test it out:
local scaleModelExample = workspace.ScaleModelExample
local initSize = scaleModelExample.PrimaryPart.Size
local goalSizeY = 11.2
local offset = getOffset(initSize.Y, goalSizeY)
local scaledSize = getOffsetSize(initSize, offset)
scaleModelExample.PrimaryPart.Size = scaledSize
for i,v in pairs(scaleModelExample:GetChildren()) do
if v ~= scaleModelExample.PrimaryPart and v:IsA('BasePart') then -- just avoids an unnecessary calculation
v.Size = getOffsetSize(v.Size, offset)
v.Position = getOffsetPosition(scaleModelExample.PrimaryPart.CFrame, v, offset) -- recycle the offset variable returned from getOffset
end
end