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

Is there a way to detect the device the player is using?

Asked by 8 years ago

I want to have a GUI run mobile ads to award players points but there's no point in having a PC player's screen's being taken up by an essentially useless GUI. Any way to detect if the local player is using a touchscreen tablet/phone?

0
http://wiki.roblox.com/index.php?title=API:Class/UserInputService there is a way to detect if a user is on mobile or not. UniversalDreams 205 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You can use the UserInputService, here's an example.

Here's how to detect if its mobile

(LocalScript)

--Made by ElmEditor
--To answer question on scriptinghelpers.org
game:GetService("UserInputService").KeyboardEnabled==false and game:GetService("UserInputService").TouchEnabled==true then --If there is no keyboard but a touch device
print 'Mobile'
elseif
game:GetService("UserInputService").KeyboardEnabled==true and game:GetService("UserInputService").TouchEnabled==false then --No touch device but a keyboard
print 'Computer/Laptop'
else --If its not Computer/Laptop or Mobile
print 'Xbox or other' --It'd be Xbox
end
--Must be localscript

Note: If somebody is playing on a gamepad and keyboard is enabled it'd print "Computer/Laptop", but if they are playing on Gamepad w/ Touch Device it'd print Mobile. You can add other detections if you'd like.

Hope this helps, if it did press that ^ button; it helps alot!

-ElmEditor

Ad

Answer this question