How do i check if a player is on mobile

How do I check if a player is on mobile or not?
I need to know this because some GUIs need to appear on mobile and some GUIs
don’t or is there an easier way to do this without knowing what device the player is on?

Make the size of your GUIs scale, not offset.

So that is something you can fix by doing the following things mentioned in some of the replies on the following devforum post

and also

set anchor point to 0.5 on both axis(NOTE THAT THIS WILL OFFSET IT AND YOU WILL NEED TO REPOSITION IT)

The OP said they wanted some GUIs to appear and some not, not to scale GUIs.

As for the OP, the UserInputService service has two properties that can be helpful in trying to determine the platform, albeit kind of a ‘hacky’ method.

The two properties are TouchEnabled and MouseEnabled.

One can write a function to utilize these, a little like so:

local uis = game:GetService("UserInputService");
function getPlatform()
    if(uis.MouseEnabled and not uis.TouchEnabled) then
        return "PC";
    elseif(uis.TouchEnabled and not uis.MouseEnabled) then -- does not check for console, so having an 'else' could potentially fire for console players, thus returning inaccurate data.
        return "Mobile";
    end
end
1 Like

Ohhh didn’t realize I thought she meant she wanted the guis smaller on mobile to fit on screen :man_facepalming:t2:

I personally check by using UserInputService. I don’t recommend you to use it because some devices may be confused as others:

local uis = game:GetService("UserInputService");
if uis.TouchEnabled and uis.MouseEnabled == false and uis.GamepadEnabled == false then
   -- mobile
end;

You could use the Enum:

if Enum.Platform.Windows then

elseif Enum.Platform.Enum.Platform.XBox360

etc

I think people thought that I wanted to make the GUIs smaller but what i meant was
I want to make it completely invisible if that’s possible sorry for not
explaining it properly.

Maybe do a better research?

There is no way to check what platform a player is on, but you can use these api references to help determine it:

GuiService:IsTenFootInterface
UserInputService.TouchEnabled
UserInputService.KeyboardEnabled
UserInputService.AccelerometerEnabled
UserInputService.GyroscopeEnabled
UserInputService.GamepadEnabled

UserInputService:GetPlatform works but only in CoreScripts meaning we can’t use it

Yes, you could use something like the function I provided.

local uis = game:GetService("UserInputService");
function getPlatform()
    if(uis.MouseEnabled and not uis.TouchEnabled) then
        return "PC";
    elseif(uis.TouchEnabled and not uis.MouseEnabled) then -- does not check for console, so having an 'else' could potentially fire for console players, thus returning inaccurate data.
        return "Mobile";
    end
end

if(getPlatform() == "Mobile") then
    gui.Enabled = true; -- GUI is now enabled only for Mobile
end

To check A player is on mobile or not .roblox gives a GUI called “TouchGui”(in PlayerGui), it is only given to players who are on mobile only cuz jump button is only in Touch Gui so you can use this code.

if game.Players.LocalPlayer.PlayerGui:FindFirstChild(“TouchGui”) then
print(“Oh No he is on Mobile”)
end

2 Likes