I have this monster of a function here:
function ResizeOneAxisAsymmetrically(part:PartOperation, normalId, deltaAmount)
local origExtentsCFrame = part.ExtentsCFrame
if normalId == Enum.NormalId.Top then -- 1
if part.Size.Y + deltaAmount < GridSize.Value then
deltaAmount = GridSize.Value - part.Size.Y
if boxes[part] ~= nil then
boxes[part].Color3 = Color3.new(1,1,0)
end
else
if boxes[part] ~= nil then
boxes[part].Color3 = selectionBoxDefaultColor
end
end
part.Size += Vector3.new(0, deltaAmount, 0)
part.CFrame *= origExtentsCFrame * part.ExtentsCFrame:Inverse() * CFrame.new(0, deltaAmount / 2, 0)
elseif normalId == Enum.NormalId.Bottom then -- 4
if part.Size.Y + deltaAmount < GridSize.Value then
deltaAmount = GridSize.Value - part.Size.Y
if boxes[part] ~= nil then
boxes[part].Color3 = Color3.new(1,1,0)
end
else
if boxes[part] ~= nil then
boxes[part].Color3 = selectionBoxDefaultColor
end
end
part.Size += Vector3.new(0, deltaAmount, 0)
part.CFrame *= origExtentsCFrame * part.ExtentsCFrame:Inverse() * CFrame.new(0, -deltaAmount / 2, 0)
elseif normalId == Enum.NormalId.Front then -- 5
if part.Size.Z + deltaAmount < GridSize.Value then
deltaAmount = GridSize.Value - part.Size.Z
if boxes[part] ~= nil then
boxes[part].Color3 = Color3.new(1,1,0)
end
else
if boxes[part] ~= nil then
boxes[part].Color3 = selectionBoxDefaultColor
end
end
part.Size += Vector3.new(0, 0, deltaAmount)
part.CFrame *= origExtentsCFrame * part.ExtentsCFrame:Inverse() * CFrame.new(0, 0, -deltaAmount / 2)
elseif normalId == Enum.NormalId.Back then -- 2
if part.Size.Z + deltaAmount < GridSize.Value then
deltaAmount = GridSize.Value - part.Size.Z
if boxes[part] ~= nil then
boxes[part].Color3 = Color3.new(1,1,0)
end
else
if boxes[part] ~= nil then
boxes[part].Color3 = selectionBoxDefaultColor
end
end
part.Size += Vector3.new(0, 0, deltaAmount)
part.CFrame *= origExtentsCFrame * part.ExtentsCFrame:Inverse() * CFrame.new(0, 0, deltaAmount / 2)
elseif normalId == Enum.NormalId.Left then -- 3
if part.Size.X + deltaAmount < GridSize.Value then
deltaAmount = GridSize.Value - part.Size.X
if boxes[part] ~= nil then
boxes[part].Color3 = Color3.new(1,1,0)
end
else
if boxes[part] ~= nil then
boxes[part].Color3 = selectionBoxDefaultColor
end
end
part.Size += Vector3.new(deltaAmount, 0, 0)
part.CFrame *= origExtentsCFrame * part.ExtentsCFrame:Inverse() * CFrame.new(-deltaAmount / 2, 0, 0)
elseif normalId == Enum.NormalId.Right then -- 0
if part.Size.X + deltaAmount < GridSize.Value then
deltaAmount = GridSize.Value - part.Size.X
if boxes[part] ~= nil then
boxes[part].Color3 = Color3.new(1,1,0)
end
else
if boxes[part] ~= nil then
boxes[part].Color3 = selectionBoxDefaultColor
end
end
part.Size += Vector3.new(deltaAmount, 0, 0)
part.CFrame *= origExtentsCFrame * part.ExtentsCFrame:Inverse() * CFrame.new(deltaAmount / 2, 0, 0)
end
end
Can y’all help me simplify it with functions and/or optimize it? Most of it repeats except for a few changes here and there.
Thanks!