Screen Size [WHICH MORE ACCURATE]

local function getDeviceScreenSize()
	local X = game.Workspace.CurrentCamera.ViewportSize.X
	local Y = game.Workspace.CurrentCamera.ViewportSize.Y
	local Result = ('%d , %d'):format(X, Y)
	return Result
end

local function getDeviceSize(Gui)
	local size = Gui.AbsoluteSize
	local X, Y = size.X, size.Y
	local Result = ('%d , %d'):format(X, Y)
	return Result
end

print(getDeviceScreenSize())
print(getDeviceSize(script.Parent))

Because it has different results, even though it’s so slight.
1228 , 635 - Client - LocalScript:15
1228 , 599 - Client - LocalScript:16

3 Likes

Is the getDeviceSize(Gui) getting the gui minus the topbar that appears (the inset)? If so then i would assume the larger is more accurate but i guess it depends on what you are trying to achieve.

Edit: upon reading the API it looks like i was right as the inset is 36 pixels…your difference.

2 Likes

There is always a 36 pixel gap for the Roblox TopBar like @RMofSBI said.

I prefer to use game.Workspace.CurrentCamera.ViewportSize as it’s the easiest to index but it’s all preference.

1 Like