How do i detect if a player is playing on mobile?

This may be a dumb and short question. But I just can’t find it anywhere. How am I able to tell if the player is playing on a mobile device? Is there a function for detecting their game platform or something?

Yes! There is totally a way. I think it’s somewhere on the docs, maybe this page?
https://create.roblox.com/docs/scripting/input/mobile-input

You can check the UserInputService from the client using a LocalScript.

local UIS = game:GetService("UserInputService")
local PC, Touchscreen, Controller =  (UIS.MouseEnabled and UIS.KeyboardEnabled), UIS.TouchEnabled, UIS.GamepadEnabled
if not PC and Touchscreen then
--do stuff
end
1 Like

Yes, but there is a flaw with that.
If someone is using a touchscreen computer device, then when the if statement checks and it senses the touchscreen, it’ll do the code inside. So, a PC touchscreen player might get the mobile controls… but hey i think it’ll be fine

1 Like
local UIS = game:GetService("UserInputService")
local PC, PCwithTouch, Touchscreen, Controller =  (UIS.MouseEnabled and UIS.KeyboardEnabled), (UIS.MouseEnabled and UIS.KeyboardEnabled and UIS.TouchEnabled), UIS.TouchEnabled, UIS.GamepadEnabled
if Touchscreen then
--do stuff
end

maybe this can be a workaround, i’ll see if it works

1 Like

Yeah. If a person on PC uses a touchscreen you can perform a check when they touch.

UIS.InputChanged:connect(function(InputType)
	if InputType == Enum.UserInputType.Touch then
	--display touch controls
	end
end)
1 Like

What are you trying to achieve with knowing if a player is on mobile or not? Because yes this information is visible to CoreScripts through DeviceType I have never seen a situation where developer’s needed to use it.

I’m intending to find out the device type so i can scale some ui down for mobile devices.

Just use the AbsoluteSize property of your ScreenGui and then make it work on any small screen, not just ones that are specifically on a mobile device.

No, there isn’t a function to detect the device from the player, I recommend your game to adjust to every type of input type, for example, if there’s no keyboard, then adding touch support and not just assuming that a mobile device doesn’t have keyboard, basically I mean that you must add support for every input type instead of checking the player device to add certain features to the game.

	if UIS.KeyboardEnabled and UIS.MouseEnabled then
       print("User is on computer")
	elseif UIS.TouchEnabled then
       print("User is on mobile")
	end
1 Like