Find if player is on mobile or computer

Hello,

I scripting a train driving system who gives Gui but when the player is on mobile, the Gui will be not the same than a computer player.
The script who gives it is a Server Script, how can i check if player is on mobile on this server script ?

Enjoy !

1 Like

You can’t, I don’t think Roblox has a way to check the device type. However, you can check the player’s input method.

1 Like
local IsMobile     =   not UserInputService.KeyboardEnabled 
                       and not UserInputService.MouseEnabled 
                       and not UserInputService.GamepadEnabled 

RemoteEvent:FireServer(IsMobile) -- true if player in mobile false if not
3 Likes

Just to elaborate for completeness - here’s the code used by GameAnalytics in their client module.
Not sure which solution is more correct but my GA stats have always matched what Roblox say…

(Clientscript)

--Services
local GS = game:GetService("GuiService")
local UIS = game:GetService("UserInputService")


--Functions
local function getPlatform()

    if (GS:IsTenFootInterface()) then
        return "Console"
    elseif (UIS.TouchEnabled and not UIS.MouseEnabled) then
        return "Mobile"
    else
        return "Desktop"
    end
end
1 Like

This isn’t very effective. At least with the console detection.

It is more effective to do something like this:

local uis = game:GetService("UserInputService")

if uis.TouchEnabled and not uis.KeyboardEnabled then
    print("Mobile")
elseif uis.KeyboardEnabled and not uis.TouchEnabled then
    print("Computer")
elseif uis.GamepadEnabled and not uis.TouchEnabled and not uis.KeyboardEnabled then
    print("Console")
end
11 Likes

What will your example do with a touch enabled Computer?

It will do whatever it is programed to do. A computer normally can’t be put into touch mode. But, if you test in studio (with mobile screen test enabled), it will enable touch input. With that, if you have buttons for only mobile (like a sprint button), it will show up.

In any other case, unless the computer is a laptop and allows roblox to be played in touch when folded into tablet mode, if no keyboard is enabled, nothing will happen at all

You could also add a UserInputService.MouseEnabled check to see if a mouse is connected (a bit of additional information to help figure out the platform)

1 Like

The Player Maybe in Pc Have Touch Screen And Xbox Controller and he have His mouse unPlugged ,how u gonna deal with that?

2 Likes

u can use Sleitnick input module he have the solution for this problem in the PreferredInput and it’s easy to use

Thanks everyone, your answers was helpfull. I succeeded, i finally used a RemoteEvent to send my “give gui request” to a localscript who check the player device (with the @AmoraFolf 's method) and gives it !

1 Like

Touch screen computers usually don’t do anything. The only computer I can think of that will actually change to touch input is on a chromebook lol. Folding one into tablet mode will change the game into touch input mode. Chromebooks do this with all mobile apps installed on them since they all have the google play store. It’s part of a chromebooks functionality, and from my knowledge, no other laptop will do that.


Having a controller enabled is a bit of a concern, but all it does is consider it a console. If they use their keyboard at any time, it switches the input mode to keyboard, and if they use the controller again, it switches back to gamepad input. It will not cause any issues at all.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.