Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 9 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 5487 Badge of Merit Moderation Voter Community Moderator
9 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
9 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