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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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

Ad
Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You can't do exactaly that, but you can detect if user have touch enabled on his/her device.

local userInputService = game:GetService("UserInputService")

if userInputService.TouchEnabled then
    print("The user's device has a touchscreen!")
else
    print("The user's device does not have a touchscreen!")
end

(extracted from https://developer.roblox.com/en-us/api-reference/property/UserInputService/TouchEnabled)

Log in to vote
0
Answered by 3 years ago

Wow. Thanks guys ^^

It managed to fix my issue.

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

Answer this question