Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to scale models properly through script using Attributes?

Asked by 2 years ago

So anyways

I need to scale models using attributes

which will be a vector3 value

these are the same 2 models with different vector3 values in size for the attribute

how would i properly scale them without using anything else like an iv loop to make them the same size of each part

For example if a model is 10 ,10,10

and another model i want to scale to is 50,50,50

I want the model to become from 10,10,10 to 50,50,50

while still maintaining the scale of all the parts in the model

I tried dividing 50/5 and using the value of 5 to multiply the size of 50,50,50 to every single part

now the problem is that since i do this to every part it ends up becoming bigger

does anyone know how I can get this to work?

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

Good news for you, Roblox just announced that they will add a new Model:ScaleTo() function 8 days ago from this post.

1local size = 10
2Model:ScaleTo(size)

However, Roblox hasn't officially released it yet as it is still pending (from this page). Be patient until it goes live.

In the meantime, try this code that I got from this guy. (credits btw)

01function ScaleModel(model, xScale, yScale, zScale)
02    local cf, _ = model:GetBoundingBox()
03    local origin = cf.Position
04 
05    local scale = Vector3.new(xScale, yScale, zScale)
06 
07    for _, obj in pairs(model:GetDescendants()) do
08        local OriginalSize = obj:GetAttribute("OriginalSize")
09        if OriginalSize == nil then
10            if obj:IsA("BasePart") then
11                obj:GetAttribute("OriginalSize", obj.Size)
12            elseif obj:IsA("JointInstance") then
13                obj:GetAttribute("OriginalSize", Vector.zero)
14            elseif obj:IsA("SpecialMesh") then
15                obj:GetAttribute("OriginalSize", obj.Scale)
View all 56 lines...
Ad

Answer this question