I got this code that detects what device you are (to a degree) and I’m having problems with the PC detection. Problem is, if I am trying to use the emulators, doing if KeyboardEnabled then PC does not work, as it still returns true.
This issue could also arise if a user has a touch screen monitor (I assume those also return TouchEnabled true?)
So what I am wanting is, if keyboard is enabled AND TouchEnabled == false (if not in studio)
So basically, in studio, if I am using a mobile emulator, it should return the correct device, while if I play in proper game, it should return PC. Atm, it returns Tablet when I test in proper game.
return function()
if GuiService:IsTenFootInterface() or UserInputService.GamepadEnabled then -- On a console (or using controller)
return "Console", false
end
print((RunService:IsStudio() and not UserInputService.TouchEnabled))
if UserInputService.KeyboardEnabled and (RunService:IsStudio() and not UserInputService.TouchEnabled) then -- Have a keyboard (must be PC)
print("PC")
return "PC", false
end
if Camera.ViewportSize.Y > 500 then -- On tablet
return "Tablet", UserInputService.TouchEnabled
end
return "Mobile", UserInputService.TouchEnabled
end
Is there any reason you’re trying to detect the exact device?
I would just use all those functions directly, the device type itself doesn’t really give you that much info.
The mobile emulator isn’t lying—you can plug a controller into a PC or connect your phone to a Bluetooth keyboard. So the emulator is just acting like a phone with a keyboard attached.
Reasons are mainly UI based. I need to know what style device you on to base UI on. Mobile needs to have UI scaled a certain way, compared to tablet and PC, etc.
Usually you would want to detect the Screen size if you want to layout GUI not check for input types.
Usually checking for input types is used when knowing whether or not to put touch controls down or not.
Even better (but probably a little harder to implement and design) would be a system where the user could chose which device they are on like in MM2 where you can choose between tablet and phone. You can also extend this by giving the player the ability to control where the buttons are placed on the screen.
Hope this helps.
Also one very very small improvement
I know this isn’t accessible from normal localscripts
You don’t specifically need to actually scale the gui itself, there are multiple ways doing it without using code, like the “AutoScale lite” plugin. Otherwise, sorry, I can’t really help with that.
I do use AutoScale. It was it’s drawbacks though. I’m meticulous with UI, and it has to be flawless across all devices. Scaling and whacking a aspectratio into it doesn’t always offer great quality UI across devices