Is there any way to get the size of a users' screen in a unit such as millimetres, centimetres, inches, etc.? I am trying to create GUIs that will display on the screen as a specific size.
Example: I want a display to be 10x12 cm on all displays, regardless of the size or resolution of the display.
Edit below:
Take two example displays with an X resolution of 1920: Display1 Width: 10 inches Display2 Width: 20 inches
Pixel density (PPI) of the displays (resolution/size): Display1: 192px/in Display2: 96px/in
A frame on both displays with a width scale of 0.5 (1920/2PPI or WidthInInchesscale) Display1 Frame Width: 5in Display2 Frame Width: 10in
5 ~= 10
This is the problem I want to solve. I do not want the GUI to scale to the display. I also do not want to base it off of pixels because of variation in pixel density.
Using the previous example displays, a frame with a width of 500px: Display1 Frame Width: 2.6in (approximation) Display2 Frame Width: 5.2in (approximation)
Using the default sizing and positioning type of UDim2, you can scale the gui so that it is in the right location. Each screen is a different size, but roblox has already done the work for you. All you have to understand is that 0 is 0 and 1 is the other end of the screen for both the width(X) and height(y).
UDim2.new(number xScale, int xOffset, number yScale, int yOffset)
tb = Instance.new("Textbox") tb.Parent = game.StarterGui tb.Position = UDim2.new(0.5, 0, .5, 0) -- Will put top left corner of textbox in the middle of the screen
If you wish to get the exact size in pixels...
You will need to get the mouse from the local player(I'm using a local script in this example)
local mouse = game.Players.LocalPlayer:GetMouse()
Then, you can obtain the the width using mouse.ViewSizeX and the height of the screen using mouse.ViewSizeY
while true do wait(.1) print(mouse.ViewSizeX .. ", " .. mouse.ViewSizeY) end
I added in a loop so you can test this in studio by resizing the side bars while in play solo
(Whole Script)
mouse = game.Players.LocalPlayer:GetMouse() while true do wait(.1) print(mouse.ViewSizeX .. ", " .. mouse.ViewSizeY) end
Credits to Legojoker's reply here(give him an upvote if this helps!): https://scriptinghelpers.org/questions/23265/how-big-is-the-roblox-screen
*Always try look up other scripting helper questions before posting your own in case its already been answered
Hope this helps. Let me know if this still isn't what you were exactly looking for.