I was wondering if there was a certain type of code where it only happens with a certain device. If you still don't know what i mean, for people who play on mobile, when you play jail break, there is a GUI what only shows for mobile to sprint or crouch,
Thanks, SUPERKID8713
PS. if you want to play my game the link is https://web.roblox.com/games/6493517966/Sword-Fight-Beta, i might need to restart because of how broken it is but play it for now!
I found this link on the devforum about an existing topic: https://devforum.roblox.com/t/how-to-detect-if-player-is-using-a-phone/178533
You can use UserInputService
and GuiService
to determine whether a player is on mobile or not.
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local GServ = game:GetService( "GuiService" ) |
03 | local te = UIS.TouchEnabled -- can you touch the screen? |
04 | local ke = UIS.KeyboardEnabled -- is there a keyboard? |
05 | local me = UIS.MouseEnabled -- is there a mouse? |
06 | local ge = UIS.GamepadEnabled -- is there a gamepad? |
07 | local tenfoot = GServ:IsTenFootInterface() -- is tenfootinterface enabled? (a roblox ui exclusive to console) |
08 | if te and not ke and not me and not ge and not tenfoot then |
09 | -- your code because its a mobile device |
10 | end |
11 |
12 | --[[ |
13 | same thing with detecting consoles and pc's |
14 |
15 | if ke and me then |
https://developer.roblox.com/en-us/api-reference/class/UserInputService
https://developer.roblox.com/en-us/api-reference/class/GuiService
Hope this helps
There's no native way to get the user's device type. However, there are some functions that may interest you:
UserInputService.AccelerometerEnabled
UserInputService.GamepadEnabled
UserInputService.GyroscopeEnabled
UserInputService.KeyboardEnabled
UserInputService.MouseEnabled
UserInputService.TouchEnabled
UserInputService.VREnabled
GuiService::IsTenFootInterface
Mobile devices have MouseEnabled and KeyboardEnabled false. Most mobile devices should have an accelerometer and gyroscope.
Console devices have KeyboardEnabled false, and IsTenFootInterface true.
I may have missed some functions or properties from the wiki, but you can explore yourself.
Also, here's a snippet of code I found on the DevForums, I forgot who the original author was, so I apologize if it was your's.
01 | local GuiService = game:GetService( "GuiService" ) |
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | function getplatform() |
04 | if (GuiService:IsTenFootInterface()) then |
05 | return "Console" |
06 | elseif (UserInputService.TouchEnabled and not UserInputService.MouseEnabled) then |
07 | --touchscreen computers now have touchenabled so make sure to check for lack of mouse too |
08 | --also, not all phones/tablets have accelerometer and/or gyroscope |
09 | local DeviceSize = workspace.CurrentCamera.ViewportSize; |
10 | if ( DeviceSize.Y > 600 ) then |
11 | return "Mobile (tablet)" |
12 | else |
13 | return "Mobile (phone)" |
14 | end |
15 | else |
16 | return "Desktop" |
17 | end |
18 | end |