How to check if a player is mobile or pc

Hey! I was wondering how to check if a player was mobile or pc because I want to give mobile players a special gear.

6 Likes

You can use UserInputService | Roblox Creator Documentation for this

local UserInputService = game:GetService("UserInputService")

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	print("Mobile device")
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	print("Computer device")
end
31 Likes

Wait so like I’d say player.UserInputService orrrr… thanks btw this helps a lot XD :smiley:

1 Like

You can only do that in a local script.

Ok but like what do I put in my script like if player.UserInputService or just like uhm what?

Put it like I said above and use a RemoteEvent | Roblox Creator Documentation to give the player the special gear.

LocalScript in StarterPlayerScripts

local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("RemoteEvent") -- Put the remote event here, you can name it whatever you want

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	RemoteEvent:FireServer()
end

Script in ServerScriptService

local RemoteEvent = game.ReplicatedStorage:FindFirstChild("RemoteEvent")
local Gear = game.ServerStorage:FindFirstChild("Gear")  -- Put the gear here and change it to the name of your gear

RemoteEvent.OnServerEvent:Connect(function(player)
	Gear:Clone().Parent = player.StarterGear
	Gear:Clone().Parent = player.Backpack
end)
1 Like

cc @BMWLux

An important note when making checks like this is that mobile devices CAN have a keyboard and pc devices CAN have a touch screen. There is no 100% accuracy check.

In reality, you shouldn’t be trying to infer device type in most cases. Adapt to the form of input the user wants to use, not what you think they should use.

4 Likes

How would I detect console players with this method?

Like this @iBuzzes?

local UserInputService = game:GetService("UserInputService")

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	print("Mobile device")
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	print("Computer device")
elseif UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	print("Computer device with touchscreen")
elseif UserInputService.GamepadEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	print("Console device")
end
4 Likes

Yes, I think that should work.

1 Like