Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Hey! Is there a certain type of code where it only happens for certain devices?

Asked by 4 years ago

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!

0
yeah Configuator 158 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

01local UIS = game:GetService("UserInputService")
02local GServ = game:GetService("GuiService")
03local te = UIS.TouchEnabled -- can you touch the screen?
04local ke = UIS.KeyboardEnabled -- is there a keyboard?
05local me = UIS.MouseEnabled -- is there a mouse?
06local ge = UIS.GamepadEnabled -- is there a gamepad?
07local 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
10end
11 
12--[[
13same thing with detecting consoles and pc's
14 
15if ke and me then
View all 22 lines...

https://developer.roblox.com/en-us/api-reference/class/UserInputService

https://developer.roblox.com/en-us/api-reference/class/GuiService

Hope this helps

Ad
Log in to vote
1
Answered by
ud2v3cf 35
4 years ago

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.

01local GuiService = game:GetService("GuiService")
02local UserInputService = game:GetService("UserInputService")
03function 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
18end

Answer this question