New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How would I get the current size of my screen (in pixels)?

Asked by 4 years ago

Title says it all. I really have no idea what to try. Thanks in advance.

2 answers

Log in to vote
0
Answered by
adark 5386 Badge of Merit Moderation Voter Community Moderator
4 years ago

Using the PlayerMouse Object from a GetMouse method of a Player:

--LocalScript

local mouse = game.Players.LocalPlayer:GetMouse()
local screenSize = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)

Although this won't be accurate if the user resizes their screen, so:

--LocalScript

local mouse = game.Players.LocalPlayer:GetMouse()
local screenSize = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)

game:GetService("RunService").RenderStepped:connect(function()
    local newSize = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
    if newSize ~= screenSize then
        screenSize = newSize
    end
end)
Ad
Log in to vote
0
Answered by
bobder2 135
4 years ago

You could also use a ScreenGui. They have a readonly variable called AbsoluteSize which is in pixels and is the size of the window, not including the border.

Answer this question