Hey!
I want to show you a script I just made to make the UI autoscale.
This script will help you make your GUI fit for all the Screens. For that just follow the following steps:
local Frame = script.Parent --Frame To Scale
local Proporcionality = Vector2.new(0.75,1) --Frame proportions (over 1)
local Camera = workspace.Camera or workspace:WaitForChild("Camera") --Don't touch
local ReductionRat = 0.8 --Reduction Ratiio (Is recomendable to don't touch)
Camera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
local NewViewportSize = Camera.ViewportSize
local Widther = (NewViewportSize.X/Proporcionality.X)>=(NewViewportSize.Y/Proporcionality.Y)
if Widther then
local SizeY = math.floor(NewViewportSize.Y/Proporcionality.Y)*ReductionRat
Frame.Size = UDim2.fromOffset(Proporcionality.X*(SizeY*Proporcionality.Y)/Proporcionality.Y,SizeY*Proporcionality.Y)
else
local SizeX = math.floor(NewViewportSize.X/Proporcionality.X)*ReductionRat
Frame.Size = UDim2.fromOffset(SizeX*Proporcionality.X,Proporcionality.Y*(SizeX*Proporcionality.X)/Proporcionality.X)
end
end)
1. Insert the script parented directly with the UI element you want to autoscale 2. Set all it descendants size to only scaled size 3. Go to the third like of the script and write the proportionality your frame must have (over 1). For example, if your frame has a size of (200,400), you will need to put Vector2.new(0.5,1), or if your frame has a size of (60,90), you will have to put Vector2.new(0.666,1), The highert value will always be sustitued by 1 and the other one by the division of itself by the higher.
Now it should work perfectly!
Enjoy your autoscalable frame! Optional: You can change the reduction ratio to make it bigger or smaller.
Well, I made it to show the people how can they make it if they want to do smt that the UIAspectRatio don’t allows. The point of making this, is give the flexivility of variate the UIAspectRatio.
With this, nothing. As I said, the idea is the people to modify if they need more flexivility. I just want to show a way of doing it. More times I feel stuck with a logic math problem and lose around 20 min, I just want the people to be able to solve it by just searching it on the dev forum, what takes much less than thinking it.
Id why a car company would make a page about it, but there isn’t in roblox any fueature called “Responsive UI”, no? I mean, (I have not readed the pages) but I don’t think they include smt about roblox and roblox don’t include it on it’s docs.
I have run into such issues and I frankly hate working with UI constraints on Roblox. I have taken the approach of using offset almost exclusively, with sizing functions
You can make yourself a “BaseOffset” variable of some sort, which is calculated from the screen size, and used to set the size of all the UI elements
Setting the size of the parent depending on childrens is much easier
You can make more complex stuff like determining the amount of slots in a UI depending on the size of the UI and threshold values
I am someone who likes having a lot of control over what I do, and using offset gives me that control