Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a script activate only for users using a phone/tablet?

So if the user is using a computer, they can't use the script, but if the user is using a phone, then they can.

If someone could atleast guide me in the right direction, that would be great.

function setKey(input)
	if input.KeyCode == Enum.KeyCode.A then

I'm guessing something like this could help.

3 answers

✓ Accepted answer

To continue on @Leamir's code, you can also detect if KeyboardEnable is false and MouseEnable just in case their computer is a touch screen!

local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled then

   -- mobile device

end

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

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

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

Wow. Thanks guys ^^

It managed to fix my issue.

I actually hope this helps others too, if they had a similar problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.