How would I make a script that manually scales a GUI depending on the client's screen size?

Hello, I am working on a script that reads players’ screen size, and manually changes the size of a GUI. How it would work is that there are ranges in a script that would determine the scale of a GUI. Whichever range the client’s screen size falls into would change the GUI to that size. However, I do not know an efficient way of doing this. (For example, using elseif statements would make for a very long and messy script.) Does anyone know a more effective way of reading a player’s screen size and assigning a size to a gui?

Code for getting client screen size for anyone who needs it:

local WorkspaceService = game:GetService(“Workspace”)

local CurrentCamera = WorkspaceService.CurrentCamera.ViewportSize

1 Like

There already is a global variable for workspace.

If you want to get the screen size of a player you have to use the following code (client-sided code):

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
x = mouse.ViewSizeX
y = mouse.ViewSizeY

ViewportSize is for ViewportFrames by the way.

Don’t use mouse to get the size.

Camera.ViewportSize does return the size of the screen.

Yeah, I already knew that… I was just following the Youtube video I was watching lol. Anyway, how could I use this to determine the size of a GUI?

I don’t understand, i would suggest using Scale, for example. 0.5, 0, 0.5, 0 gets half screen of the client. By the way, if you convert the scale to offset you will get better results.

You don’t need any scripts for this. You can use scale and it’ll scale to the user’s screen. If you want to keep the aspect ratio of the gui while it scales you can use UIAspectRatio constraint

The only things you might want to script is making the guis a bit bigger if the player’s on mobile or XBOX, but aside from that no scripting needed.

The thing is, I’m using a plugin that helps me create custom GUI, and it scales weird on different devices, so I have to do it manually.