Here’s the maintained version of the module
--!strict
local function multiplyComponents(cframe: CFrame, multiplier: number): CFrame
local components = {}
for index, value in ipairs(table.pack(cframe:GetComponents())) do
table.insert(components, index, value * multiplier)
end
return CFrame.new(table.unpack(components))
end
return function(model: Model, scale: number)
assert(typeof(model) == "Instance" and model:IsA("Model") and model.PrimaryPart, "Argument 1: You must pass a model with primary part set to rescale!")
assert(type(scale) == "number", "Argument 2: scale must be a number!")
local parts: {BasePart}, positions: {Vector3}, sizes: {Vector3} = {}, {}, {}
local savedJointInstance: {[JointInstance]: {[string]: any}} = {}
local descendants: {Instance} = model:GetDescendants()
local primaryPart: BasePart = model.PrimaryPart
local partToUnanchor: {BasePart} = {}
for _, descendant in ipairs(descendants) do
if descendant:IsA("BasePart") then
table.insert(parts, descendant)
table.insert(positions, descendant.Position)
table.insert(sizes, descendant.Size)
if not descendant.Anchored then
table.insert(partToUnanchor, descendant)
descendant.Anchored = true
end
elseif descendant:IsA("JointInstance") then
savedJointInstance[descendant] = {
C0 = descendant.C0,
C1 = descendant.C1,
Enabled = descendant.Enabled,
Part0 = descendant.Part0,
Part1 = descendant.Part1
}
end
end
local objectPositions = table.pack(primaryPart.CFrame:PointToObjectSpace(table.unpack(positions)))
local scaleMatrix = CFrame.new(0, 0, 0, scale, 0, 0, 0, scale, 0, 0, 0, scale)
local primaryCFrame = primaryPart.CFrame * scaleMatrix
local newPoints = table.pack(primaryCFrame:PointToWorldSpace(table.unpack(objectPositions)))
local newSizes = table.pack(scaleMatrix:PointToWorldSpace(table.unpack(sizes)))
local newCFrames: {CFrame} = {}
for index, part in ipairs(parts) do
if newSizes[index] then
part.Size = newSizes[index]
end
if newPoints[index] then
table.insert(newCFrames, index, part.CFrame - part.CFrame.Position + newPoints[index])
end
end
for jointInstance, properties in pairs(savedJointInstance) do
for propertyName, propertyValue in pairs(properties) do
if propertyName == "C0" or propertyName == "C1" then
(jointInstance :: any)[propertyName] = multiplyComponents(propertyValue, scale)
else
(jointInstance :: any)[propertyName] = propertyValue
end
end
end
workspace:BulkMoveTo(parts, newCFrames)
for _, part in ipairs(partToUnanchor) do
part.Anchored = false
end
end
An example script
local RescaleModel = require(script:WaitForChild("RescaleModel"))
RescaleModel(script.Parent, 2)