Hello,
The title says all, I need it to match the GUI style for different screen sizes because for example GuiObject.BorderSizePixel looks wierd on small screens.
workspace.CurrentCamera.ViewportSize
ScreenGui has an AbsoluteSize property that you can use to get the size of the screen. Example script:
local size = ScreenGui.AbsoluteSize
local x = size.X
local y = size.Y
print("The screen size is", x, "by", y.)
I’d like to point out that nowadays this only outputs (1,1).
This is only true if you’re executing the code from the server.
You have to execute it on the client to get the client’s screen size…
So how do you use workspace.CurrentCamera.ViewportSize to make sure that every screen size (phone, tablet, computer, and console) all see the same GUI but perfectly scaled to their screen?
I’m having this issue as I’ve optimized my GUI for phones and tablets to look great since the majority of my players will play on those platforms, but it looks off center on computer and console in order to look good on mobile.
How can I make it so the GUI fits the screen size using workspace.CurrentCamera.ViewportSize somehow to make the GUI look perfect on all platforms (phone, tablet, computer, console, VR) without affecting others platforms?
If that’s the case then make a RemoteFunction from Server > Client > Server
, asking the client for a screen size (in pixels) to then be transmitted back to the server.
And to note, if you want UI to be scaled to any device, in the UDim2 value for sizing, stop using offset (The numbers in {0,x},{0,x}
), and instead use scale (The numbers in {x,0},{x,0}
).
Oh, I wasn’t asking for anything, I was just correcting the guy above
thank you!! This helped a ton and fixed my issue