I have this code that I use to check what device a user is on, and it properly detects my device when I play my published game, but whenever I am trying to test the game in studio using the device emulator, i noticed that it doesn’t return the correct values until after i send in the first input.
local GS = game:GetService("GuiService")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local Detect = {}
function Detect:GetDevice(MobileSpecific:boolean)
local Device = nil
if (GS:IsTenFootInterface()) then
Device = "Console"
elseif (UIS.TouchEnabled and not UIS.MouseEnabled) then
if MobileSpecific then
local DeviceSize = workspace.CurrentCamera.ViewportSize;
if ( DeviceSize.Y > 600 ) then
Device = "Mobile(Tablet)"
else
Device = "Mobile(Phone)"
end
else
Device = "Mobile"
end
else
Device = "Desktop"
end
return Device
end
return Detect
Test Code Running the module:
local Modules = game:GetService("ReplicatedStorage"):FindFirstChild("Modules")
assert(Modules,"Module Folder is Missing")
local DeviceModule = Modules:FindFirstChild("DeviceDetection")
assert(DeviceModule,"Device Detection Module is Missing")
local DeviceDetection = require(DeviceModule)
print(DeviceDetection:GetDevice())
wait(5)
print(DeviceDetection:GetDevice())
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Wait()
print(DeviceDetection:GetDevice())
Output if i wait until the test prints out the first two lines before applying an input:
Output if i apply an input before the second line prints:
Expected behavior
The Expected Output of this is for it to always return the correct device that I am using, but it seems that it only does this in the live game, and not the emulator, and I believe that it is due to the values that I use to check the device type not being correctly updated until after an input for some reason.
A private message is associated with this bug report

