Grid Line shifted by 1px after screen size changed

Hello, I have been working on my EFT-Styled inventory system.
I encountered a problem when viewport size changed the grid line shifted by 1 pixel.
[Before change]


[After change]

Here is my code for creating the grid line:

	local GridLines = {}

	for Column = 1, Width - 1 do
		local Line = LineTemplate:Clone()

		Line.Size = UDim2.new(0, 1, 1, 0)
		Line.AnchorPoint = Vector2.new(0.5, 0.5)
		Line.Position = UDim2.fromScale(Column / Width, 0.5)

		Line.Parent = StrokesLayer
		table.insert(GridLines, Line)
	end

	for Row = 1, Height - 1 do
		local Line = LineTemplate:Clone()

		Line.Size = UDim2.new(1, 0, 0, 1)
		Line.AnchorPoint = Vector2.new(0.5, 0.5)
		Line.Position = UDim2.fromScale(0.5, Row / Height)

		Line.Parent = StrokesLayer
		table.insert(GridLines, Line)
	end

Screen size changes can sometimes cause pixel shifts due to the number of pixels not being divided evenly. For example, your column grid lines are placed at at 0.25, 0.5, 0.75 on the x scale. If your grid is sized 100 pixels this will place correctly at position 25,50,75, but if your grid is sized 99 then it won’t divide exactly and it will be placed at 24.75, 50.5, 74.25. The computer can’t place between pixels so it has to round, causing a 1 pixel offset.

Is there a solution to this? Each cell is 50 px in size.

No, this is sadly just how UI scaling works. Without more resolution, you can’t manifest more pixels to align to.

Found an alternative, I just used UIStroke directly on the cell instead of grid line.