Properly Scaling a Part

I have a script that scales down a random part in a folder. I want to scale it down from the top, but it scales it down on the top and bottom. This is how it looks: image
Here’s the script:

local C = script.Parent.Folder:GetChildren()

while true do
	for i = 1,#C do
		local Y = math.random(2, 4)
		if C[i].Name == "Tile" then
			while true do
				local Tile = C[math.random(1, #C)]
				Tile.Size = Vector3.new(9.5, Tile.Size.Y - Y, 9.5)
				Y = math.random(2, 4)
				wait(.001)
			end
		end
	end
	wait()
end

You need to adjust the position of the part when you change the size.

If you change the Y axis by 2 studs, then you need to push the part up by 1 stud (sizeChange / 2)

p.Size -= Vector3.new(0,2,0)
p.CFrame *= CFrame.new(0,1,0)

Btw, what does _= and *= mean? I looked on the operators page on the DevHub and on the Lua page, but I couldn’t find them.

The tiles go through the ground.

local function CustomResize(Part,NormalID,Delta)
	local Normal = Vector3.FromNormalId(NormalID)
	local Invert = Normal.X+Normal.Y+Normal.Z

	local NewSize = Part.Size + (Normal * Delta * Invert)

	if ((NewSize.X < 0.05) or (NewSize.Y < 0.05) or (NewSize.Z < 0.05)) then return end

	Part.Size = NewSize
	Part.CFrame *= CFrame.new(Normal * Delta * 0.5)

	return true
end

You can use this custom resize function.

Example usage:

CustomResize(Part, Enum.NormalId.Bottom, 2)
local x = 2
x *= 2

is same as

local x = 2
x = x * 2

This is what I put:

local C = script.Parent.Folder:GetChildren()

while true do
	for i = 1,#C do
		local Y = math.random(2, 4)
		if C[i].Name == "Tile" then
			while true do
				local Tile = C[math.random(1, #C)]
				local function CustomResize(Tile,NormalID,Delta)
					local Normal = Vector3.FromNormalId(NormalID)
					local Invert = Normal.X+Normal.Y+Normal.Z
					local NewSize = Tile.Size + (Normal * Delta * Invert)
					if ((NewSize.X < 0.05) or (NewSize.Y < 0.05) or (NewSize.Z < 0.05)) then return end
					Tile.Size = NewSize
					Tile.CFrame *= CFrame.new(Normal * Delta * 0.5)
					return true
				end
				CustomResize(Tile, Enum.NormalId.Bottom, 2)
			end
		end
	end
	wait()
end

It is still not working.