function Sort(NumberOfFrames,Pattern)
HideAll()
local Matched = 0
SFrame.CanvasSize = UDim2.new(0,0,(SFrameSize*(math.ceil((NumberOfFrames/2)))),0)
for i,Frame in pairs (script.Parent.Shop.Items:GetChildren()) do
local Match = string.match(Frame.Name,Pattern)
if Match then
Matched = Matched +1
Frame.Size = UDim2.new(.45,0,(ProductSize/(math.ceil((NumberOfFrames/2)))),0)

if Matched/2 ~= math.ceil(Matched/2) then
Frame.Position = UDim2.new(.025,0,Frame.Size.Y.Scale*((math.ceil(Matched/2))-1),0)
else
Frame.Position = UDim2.new(.525,0,Frame.Size.Y.Scale*((Matched/2)-1),0)
end

Frame.Visible = true
end
end
end

Also tried this:

function Sort(NumberOfFrames,Pattern)
HideAll()
local Matched = 0
SFrame.CanvasSize = UDim2.new(0,0,(SFrameSize*(math.ceil((NumberOfFrames/2)))),0)
for i,Frame in pairs (script.Parent.Shop.Items:GetChildren()) do
local Match = string.match(Frame.Name,Pattern)
if Match then
Matched = Matched +1
Frame.Size = UDim2.new(.45,0,(ProductSize/(SFrame.CanvasSize.Y.Scale/SFrame.Size.Y.Scale)),0)
if Matched/2 ~= math.ceil(Matched/2) then
Frame.Position = UDim2.new(.025,0,Frame.Size.Y.Scale*((math.ceil(Matched/2))-1),0)
else
Frame.Position = UDim2.new(.525,0,Frame.Size.Y.Scale*((Matched/2)-1),0)
end

Frame.Visible = true
end
end
end

What I'm trying to achieve.

There are 2 Buttons/Categories.

When you click one, it activates "Sort" which will select The Frames already made, and make them visible while making the other category's frames invisible. But if there are more frames in one category than the other, the frames are different sized.

I'm trying to make the frames stay the same size, no matter the Canvas Size. But the more # of Frames, the smaller it gets, and the more the image is deformed. What is wrong?

Yes, it has to be scaling