How to make resize system on handles pls

I’m working on a building system based on handles and I really don’t understand how to scale parts, I’ve watched other posts on a similar topic but they don’t work the way I want them to. for example in this post: Resize tool part cannot increase by entering other blocks

here is my code:

function onHandlesDrag(normal, distance)
	if SelectedPart and GhostPart then
		local delta
		if CurrentMode == "Move" then
			
			delta = distance - PreviousDistance
			
			local t = CFrame.new(Vector3.FromNormalId(normal) * delta)
			GhostPart.CFrame = t * GhostPart.CFrame
			SelectedPart.Position = Vector3.new(SnapToGrid(GhostPart.Position.X), math.max(0, SnapToGrid(GhostPart.Position.Y)), SnapToGrid(GhostPart.Position.Z))

			PreviousDistance = distance
			HandlesPart.Position = GhostPart.Position
			HandlesPart.Size = SelectedPart.Size
		elseif CurrentMode == "Scale" then
			local delta = distance - PreviousDistance
			if not OriginalSize then
				OriginalSize = SelectedPart.Size
				OriginalDistance = distance
			end
			local scaleDirection = Vector3.FromNormalId(normal)
			local scaleAmount = 1 + (distance - OriginalDistance) * 0.02
			local newSize = OriginalSize * (Vector3.new(1,1,1) + (scaleDirection * (scaleAmount - 1)))
			newSize = Vector3.new(
				math.max(GridSize, SnapToGrid(newSize.X)),
				math.max(GridSize, SnapToGrid(newSize.Y)),
				math.max(GridSize, SnapToGrid(newSize.Z))
			)
			local originalCanCollide = SelectedPart.CanCollide
			SelectedPart.CanCollide = false
			SelectedPart.Size = newSize
			if GhostPart then
				GhostPart.Size = newSize
			end

			HandlesPart.Size = newSize
			PreviousDistance = distance
		end
	end
end