Well, I ran some tests and it works fine for me. I saw what you mean by slabs getting squashed and that happens because since you’re using a regular scale (2, 2, 2) to decrease the size of a half-sized part, the proportion messes up. To keep it in sync with the proportion you’ll have to decrease the size by (2, 1, 2) or some other scale that suits better for the slab.
The other thing that I saw is that my module uses the PrimaryPart’s size to determinate which will be the target size, which gives better results for large / irregular models but may not be that good for little or regular things like a slab or door. I modified the code so you can switch, with a boolean value, between using the PrimaryPart’s size to calculate the target size or using the Model’s ExtentsSize.
--[[
Resize models keeping their relative positions
--]]
type ArrayOfParts = {[number]: BasePart} -- Parts inside this array are excluded from size or position changes
local Resize = {}
function Resize.SetSize(Model: Model, TargetSize: Vector3, DontAffectSize: ArrayOfParts?, DontAffectPosition: ArrayOfParts?, UseExtentsSize: boolean?)
local PrimaryPart: BasePart? = Model.PrimaryPart
if PrimaryPart then
local PrimaryPartCFrame: CFrame = PrimaryPart.CFrame
local SizeMultiplier: number
if UseExtentsSize then
SizeMultiplier = TargetSize / Model:GetExtentsSize()
else
SizeMultiplier = TargetSize / PrimaryPart.Size
end
for _, Part: BasePart in pairs(Model:GetDescendants()) do
if Part:IsA("BasePart") then
if DontAffectSize == nil or not table.find(DontAffectSize, Part) then
Part.Size *= SizeMultiplier
end
if Part ~= PrimaryPart and (DontAffectPosition == nil or not table.find(DontAffectPosition, Part)) then
local Distance: Vector3 = Part.Position - PrimaryPartCFrame.Position
local Rotation: CFrame = Part.CFrame - Part.Position
Part.CFrame = (CFrame.new(PrimaryPartCFrame.Position + Distance * SizeMultiplier) * Rotation)
end
end
end
else
error("Model needs a primary part to be resized.")
end
end
local function ModifySize(Model: Model, Size: Vector3, Operation: string, UseExtentsSize: boolean?): Vector3
local PrimaryPart: BasePart? = Model.PrimaryPart
if PrimaryPart then
local TargetSize: Vector3
if Operation == "+" then
TargetSize = (if UseExtentsSize then Model:GetExtentsSize() else PrimaryPart.Size) + Size
elseif Operation == "-" then
TargetSize = (if UseExtentsSize then Model:GetExtentsSize() else PrimaryPart.Size) - Size
elseif Operation == "*" then
TargetSize = (if UseExtentsSize then Model:GetExtentsSize() else PrimaryPart.Size) * Size
elseif Operation == "/" then
TargetSize = (if UseExtentsSize then Model:GetExtentsSize() else PrimaryPart.Size) / Size
end
return TargetSize
else
error("Model needs a primary part to be resized.")
end
end
function Resize.IncreaseSize(Model: Model, Size: Vector3, DontAffectSize: ArrayOfParts?, DontAffectPosition: ArrayOfParts?, UseExtentsSize: boolean?)
Resize.SetSize(Model, ModifySize(Model, Size, "+", UseExtentsSize), DontAffectSize, DontAffectPosition, UseExtentsSize)
end
function Resize.DecreaseSize(Model: Model, Size: Vector3, DontAffectSize: ArrayOfParts?, DontAffectPosition: ArrayOfParts?, UseExtentsSize: boolean?)
Resize.SetSize(Model, ModifySize(Model, Size, "-", UseExtentsSize), DontAffectSize, DontAffectPosition, UseExtentsSize)
end
function Resize.MultiplySize(Model: Model, Size: Vector3, DontAffectSize: ArrayOfParts?, DontAffectPosition: ArrayOfParts?, UseExtentsSize: boolean?)
Resize.SetSize(Model, ModifySize(Model, Size, "*", UseExtentsSize), DontAffectSize, DontAffectPosition, UseExtentsSize)
end
function Resize.DivideSize(Model: Model, Size: Vector3, DontAffectSize: ArrayOfParts?, DontAffectPosition: ArrayOfParts?, UseExtentsSize: boolean?)
Resize.SetSize(Model, ModifySize(Model, Size, "/", UseExtentsSize), DontAffectSize, DontAffectPosition, UseExtentsSize)
end
return Resize
About the door, I’m not really sure of why that happens. It may be something related to cframes or a bad part shape, which would be strange considering that the module separates rotation from position. It could also be that the glass panel is the primary part, in which case its position is not updated while the door’s position is updated or vice versa.