How do I make the GUI shrink to fit the window size?

Please understand that the sentences may be a little strange because we used a translator. sorry.

I usually use the “AutoScale” plugin to make the gui shrink or grow according to the size of the window.

But, Instance.new to create GUI, the “AutoScale” plugin could not be used for them.

I’m curious how I can make the GUI created through Instance.new transform to fit the size of the window.


local function createImageLabel(parent, assetId)
	local columnIndex = (#parent:GetChildren() - 1) % 7
	local rowIndex = math.floor((#parent:GetChildren() - 1) / 7)

	local imageLabel = Instance.new("ImageLabel")
	imageLabel.Size = UDim2.new(0, 100, 0, 100)
	imageLabel.Position = UDim2.new(0, columnIndex * 105, 0, rowIndex * 105)
	

	local thumbnailUrl = "https://www.roblox.com/asset-thumbnail/image?assetId="..assetId.."&width=420&height=420&format=png"
	imageLabel.Image = thumbnailUrl

	imageLabel.Parent = parent
	
	local aspectRatioConstraint = Instance.new("UIAspectRatioConstraint")
	aspectRatioConstraint.AspectRatio = 1
	aspectRatioConstraint.Parent = imageLabel
	
	

	return imageLabel
end

This is the script that generates the gui. I tried scaling it using “UIAspectRatioConstraint” as seen in the “AutoScale” plugin, but it didn’t work at all. Please help me… :cry: :cry:

3 Likes

Hey, you’re sizing it using offset which is the 100 in imageLabel.Size = UDim2.new(0, 100, 0, 100)

Try using imageLabel.Size = UDim2.new(0.5, 0, 0.5, 0) instead. This is called Scale and will resize on all devices so it’ll look the same.
Note that the value 1 is the whole screen so you’ll need to play around a bit to find the right size for you.

2 Likes

You are incredible. thank you!!!

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.