Documentation
vDevice:GetOrientation(): Enum.ScreenOrientation
This function returns the Screen Orientation the user is in
vDevice:GetConsoleType(): Enum.Platform
This function returns the Console Type the user is in
vDevice:GetMobileType(): Enum.DeviceType
This function returns the Mobile Device the user is in
vDevice:IsMobile(): boolean
This function returns if the user is in a mobile device
vDevice.isConsole
This property checks if the user is in Console
vDevice.isVR
This property checks if the user is in VR
vDevice.isPC
This property checks if the user is in PC
vDevice.PController
This property checks if the user is in PC and has an controller attached
Script Archive
v0.1
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
local screenSize = workspace.CurrentCamera.ViewportSize
local vDevice = {}
function vDevice:GetOrientation()
return (screenSize.X > screenSize.Y and Enum.ScreenOrientation.LandscapeSensor) or Enum.ScreenOrientation.Portrait
end
function vDevice:GetConsoleType()
if vDevice.isConsole then
local buttonA = UserInputService:GetStringForKeyCode(Enum.KeyCode.ButtonA)
if buttonA == "ButtonA" then
return Enum.Platform.XBoxOne
elseif buttonA == "ButtonCross" then
return Enum.Platform.PS4
end
end
return Enum.Platform.None
end
function vDevice:GetMobileType()
if vDevice:GetOrientation() == Enum.ScreenOrientation.LandscapeSensor then
return (screenSize.X < 600 and Enum.DeviceType.Phone) or Enum.DeviceType.Tablet
elseif vDevice:GetOrientation() == Enum.ScreenOrientation.Portrait then
return (screenSize.Y < 600 and Enum.DeviceType.Phone) or Enum.DeviceType.Tablet
end
return Enum.DeviceType.Unknown
end
vDevice.isConsole = GuiService:IsTenFootInterface()
vDevice.isVR = UserInputService.VREnabled
vDevice.isPC = ((not vDevice.isVR or vDevice.isConsole) and (vDevice:GetMobileType() == Enum.DeviceType.Unknown))
return vDevice
v0.2
--[[
vDevice
@TimeFrenzied - icon
@RobIoxArenaEvents - idea, methods and name
@VSCPlays - module
]]
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
local screenSize = workspace.CurrentCamera.ViewportSize
local vDevice = {}
function vDevice:GetOrientation()
return (screenSize.X > screenSize.Y and Enum.ScreenOrientation.LandscapeSensor) or Enum.ScreenOrientation.Portrait
end
function vDevice:GetConsoleType()
if vDevice.isConsole then
local buttonA = UserInputService:GetStringForKeyCode(Enum.KeyCode.ButtonB)
if buttonA == "ButtonB" then
return Enum.Platform.XBoxOne
elseif buttonA == "ButtonCircle" then
return Enum.Platform.PS4
end
end
return Enum.Platform.None
end
function vDevice:IsMobile()
if UserInputService.TouchEnabled and UserInputService.GyroscopeEnabled and UserInputService.AccelerometerEnabled then
if not vDevice.isPC and vDevice.isConsole or vDevice.isVR then
return true
end
end
return false
end
function vDevice:GetMobileType()
if vDevice:IsMobile() then
if vDevice:GetOrientation() == Enum.ScreenOrientation.LandscapeSensor then
return (screenSize.X < 600 and Enum.DeviceType.Phone) or Enum.DeviceType.Tablet
elseif vDevice:GetOrientation() == Enum.ScreenOrientation.Portrait then
return (screenSize.Y < 600 and Enum.DeviceType.Phone) or Enum.DeviceType.Tablet
end
end
return Enum.DeviceType.Unknown
end
vDevice.isConsole = GuiService:IsTenFootInterface()
vDevice.isVR = UserInputService.VREnabled
vDevice.isPC = (not vDevice.isVR or vDevice.isConsole or vDevice:IsMobile())
vDevice.PController = (vDevice.isPC and UserInputService.GamepadEnabled)
return vDevice
Changelogs
DISCLAIMER: THE DATE IS DEPENDENT ON THE DUBAI TIMEZONE, SO IT MAY APPEAR DIFFERENT FOR YOU
v0.1
Date: 2024-01-10T11:25:00Z
Release.
v0.2
Date: 2024-01-18T17:35:00Z
Added vDevice:IsMobile()
and vDevice.PController
[details about these are in the documentation]
Modified vDevice:GetMobileType()
to make sure the user is actually in mobile to help prevent false positives
Roadmap
- Add an option to detect if the user is in Windows or Mac