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.
local UIS = game:GetService("UserInputService") local GServ = game:GetService("GuiService") local te = UIS.TouchEnabled -- can you touch the screen? local ke = UIS.KeyboardEnabled -- is there a keyboard? local me = UIS.MouseEnabled -- is there a mouse? local ge = UIS.GamepadEnabled -- is there a gamepad? local tenfoot = GServ:IsTenFootInterface() -- is tenfootinterface enabled? (a roblox ui exclusive to console) if te and not ke and not me and not ge and not tenfoot then -- your code because its a mobile device end --[[ same thing with detecting consoles and pc's if ke and me then pc end if tenfoot then console end ]]
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.
local GuiService = game:GetService("GuiService") local UserInputService = game:GetService("UserInputService") function getplatform() if (GuiService:IsTenFootInterface()) then return "Console" elseif (UserInputService.TouchEnabled and not UserInputService.MouseEnabled) then --touchscreen computers now have touchenabled so make sure to check for lack of mouse too --also, not all phones/tablets have accelerometer and/or gyroscope local DeviceSize = workspace.CurrentCamera.ViewportSize; if ( DeviceSize.Y > 600 ) then return "Mobile (tablet)" else return "Mobile (phone)" end else return "Desktop" end end