How to have diffferent GUIs for different devices?

Hi

Edit:
the best and most effective way to have different Guis for different devices. I already know that you can use if statetements (look at code below) but, is there any other better way than doing that?

Is this relevant: (?) https://developer.roblox.com/en-us/articles/cross-platform-development

Hi
So, my question is pretty straight forward. How would I have different GUIs for different devices?

So what is the easiest way to, for example, change all GUIs in the game, or add something to different things, and then change the GUI according to what device they are using. So, the xbox buttons are marked with “A”. “B” etc etc. (like the controler buttons). And PC displays shortcut buttons, while phone does not etc.

And also, on tools, I have a magic wand, and I want there to be touch buttons for phone, but not for PC. And I want it to show buttons for Xbox etc.

Currently, the way I have done it for the magic wand tool. Is this:

    if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then

mobileGui.Enabled = true

elseif GuiService:IsTenFootInterface then

xboxGui.Enabled = true

else

pcGui.Enabled = true
    	
 end

(This is like, halfway pseudo code - but you get what I mean)

Is this the way to do it, or? Since I found this tutorial:
https://developer.roblox.com/en-us/articles/cross-platform-development
But I don’t know if it is relevant, and I didn’t understand it. So, what is the best way to do stuff like this, “quick and easy”, so it doesn’t get so messy. Is there any central way if you get me.

Thanks alot! Looking forward to your answer!

2 Likes

You can make a LocalScript that checks if player is on XBOX or Mobile and else we can say that he is on PC.

It will look like this (it’s not a code I only want you to understand what do I mean):

if player IsOnMobile then
–Show Mobile GUI.
elseif player IsOnXbox then
–Show XBOX GUI.
else
–Player is on PC or other unknown device.
end

There is great tutorial on DevForum showing how do detect that player is on Mobile Device (tablets, phones etc.) . Check it out: How to detect if Player is using a Phone? read the solution too.

2 Likes

You can use ContextActionService so that buttons for mobile only show up for mobile users. (https://developer.roblox.com/en-us/api-reference/class/ContextActionService)

2 Likes

Yeah, I already do that. But I was wondering if there are any better, more effective ways of doing it. Thanks for the reply

For consoles you can check for isTenFootGuiEnabled

1 Like

I was looking on the internet and didn’t find better article about detecting mobile device.

So that is the best way to do it?

There’s alsoPlayer.Device. And you check if it’s MacOS, Win32, iOS etc

1 Like

Typo, Meant to say .OperatingSystem ._.

1 Like

For Mobile, you can use the following code below (Credit: Jermatrtynojm)

if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled
   and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
  -- Touch screen, no keyboard, no mouse, no gamepad and no XBox, so it is mobile.
end

For XBOX, you can use a handy tool that Roblox gives you, which is GuiService:IsTenFootInterface(), this will only return true if the device is an XBox device.

Hope this helps :smiley:
– Kris

(Edit: I suggest you make variables and set them to either true or false depending on the type of device the user is on, and then later on enable/disable the guis corresponding to thosee variables)

5 Likes

I said how to detect mobiles without returning true when PC have touch screen.

1 Like

Oh, thanks :smiley: I have edited my answer.