Scaling Models Uniformly And Preserving Bone Offsets (with script)

Ok, i know this is specific, however i just struggled with figuring this out for the past like 6 hours and now that i have, there is no reason for others to have to do the same. So if you were looking for this, here you go:

-- scales a model uniformly based on its PrimaryPart and preserves bone offsets
local function ScaleModel(model: Model, scale: number)
	local primaryPart: BasePart? = model.PrimaryPart

	if not primaryPart then
		error("Model needs a PrimaryPart for uniform scaling.")
		return
	end

	local originalCFrame = primaryPart.CFrame

	for _, descendant in ipairs(model:GetDescendants()) do
		if descendant:IsA("BasePart") then
			local relativePos = originalCFrame:PointToObjectSpace(descendant.Position) * scale
			descendant.Position = originalCFrame:PointToWorldSpace(relativePos)
			descendant.Size *= scale

		elseif descendant:IsA("Bone") then
			local relativePos = descendant.Position * scale
			descendant.Position = relativePos
		end
	end
end
2 Likes