Programmatically Scaling Models

Is it possible to programmatically scale a model? For example, I would like to be able to rescale a model in code to 2x, or 3x its normal size (without breaking welds or anything else).

So similar to how a model can be scaled manually in Studio, but in code instead.

I’ve never done this myself but the first thing that comes to mind for me is dilation.


Pick any point relative to the model for the centre of dilation (represented by green point in pic). Then, iterate through every BasePart and get the directional vector of the said part relative to the centre of dilation. Multiply that vector by your scale factor. Finally, reposition and resize the part according to the scaled vector. This is probably much easier to understand in code so here is a demonstrative example:

local model = ...

--It's a good idea to make the centre of dilation the centre of the model otherwise the scaled model will have a different position
local dilationCentre = ...
local scaleFactor = 2 --This would make the image model eight times as big as the original

for i , part in pairs(model:GetDescendants()) do
     if part:IsA("BasePart") then
          local partPos = part.Position
          local offset = partPos - dilationCentre
          offset = offset * scaleFactor
          part.Position = dilationCentre + offset
          part.Size = part.Size * scaleFactor

As for welds and constraints, you would have to the multiply the offsets by the scale factor similarly to what was done with the part positions.


If I’m not mistaken, @Crazyman32 was taking this on a few weeks ago, he might be able to help you out.

1 Like

Always search your issue before posting a topic. I believe this is the thread SummerEquinox is talking about.

1 Like