UIGridLayout Offset going to 0 when scaled

Hello! I am having this issue where whenever I try and scale the UIGridLayout CellSize offset, it will just set it to 0,0. How can I fix this?

Script:

local frame = script.Parent.Parent.Parent.Parent.Parent.Parent.Container
local uiGridLayout = frame.UIGridLayout
local size = 1.4
local Debounce = false

local isScaled = false

script.Parent.MouseButton1Click:Connect(function()
	if Debounce then
		return
	end
	Debounce = true
	if not isScaled then
		-- Scale down
		uiGridLayout.CellSize = UDim2.fromOffset(uiGridLayout.CellSize.X.Offset/size,uiGridLayout.CellSize.Y.Offset/size)
		script.Parent.Image = "rbxassetid://8083630033"
		isScaled = true
	else
		-- scale up
		uiGridLayout.CellSize = UDim2.fromOffset(uiGridLayout.CellSize.X.Offset*size,uiGridLayout.CellSize.Y.Offset*size)
		script.Parent.Image = "rbxassetid://8083628348"
		isScaled = false
	end
	task.wait(0.1)
	Debounce = false
end)

If anyone knows, I will greatly appreciate any help!!!

uiGridLayout.CellSize.X.Offset

Is this and the similar properties 0 to begin with? That would cause the results of those calculations to come out as 0.

No. Both offsets are 117, but when you were to click it, it would turn it to 0.

Wrap the calculations inside math.round() as the offset properties of UDim2 values are expected to be integers.

Do you mean like this?

local frame = script.Parent.Parent.Parent.Parent.Parent.Parent.Container
local uiGridLayout = frame.UIGridLayout
local size = 1.4
local Debounce = false

local isScaled = false

script.Parent.MouseButton1Click:Connect(function()
	if Debounce then
		return
	end
	Debounce = true
	if not isScaled then
		-- Scale down
		uiGridLayout.CellSize = UDim2.fromScale(math.round(uiGridLayout.CellSize.X.Scale/size,uiGridLayout.CellSize.Y.Scale/size))
		script.Parent.Image = "rbxassetid://8083630033"
		isScaled = true
	else
		-- scale up
		uiGridLayout.CellSize = UDim2.fromScale(math.round(uiGridLayout.CellSize.X.Scale*size,uiGridLayout.CellSize.Y.Scale*size))
		script.Parent.Image = "rbxassetid://8083628348"
		isScaled = false
	end
	task.wait(0.1)
	Debounce = false
end)a