How to check player device?

What is the best way to check a player’s device whether if they’re on computer or mobile?

I’ve heard of

UserInputService:GetLastInputType()

but I’ve also heard of UserInputService - Detection of touch, keyboard, and mouse enabled.

1 Like
UserInputService:GetLastInputType()

is fine, although I dont know what roblox does if say a player has something like a macbook with a touchscreen as well as mouse and keyboard or if they have one of those things that allow you to use a keyboard with a mobile device

2 Likes

Tbh that might glitch the game and add the mobile buttons even though the player is using a laptop with a touchscreen… Do you think the other method is better?

Some time ago I did a project (discontinued) that had different controls for devices with touch and devices with keyboard and mouse.
I used the second method mentioned, and i found it worked super well!

1 Like

Laptop with a touchscreen is probably best with just the trackpad/mouse.

local UIS = game:GetService("UserInputService")
local mobile = UIS.TouchEnabled and not UIS.MouseEnabled and not UIS.KeyboardEnabled
local pc = not UIS.TouchEnabled and UIS.KeyboardEnabled
1 Like

What would happen if a laptop user has touch screen enabled and they have a mouse connected to it. Would the game break and give the user mobile buttons?

1 Like

To keep it simple in your case could try something simple like this that also updates the device itself aswell:

local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local function DetectPlatform()
	if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled then
		Player:SetAttribute("Platform", "Mobile")
	elseif GuiService:IsTenFootInterface() then
		Player:SetAttribute("Platform", "Console")
	else
		Player:SetAttribute("Platform", "PC")
	end
end

-- Platform Detection
DetectPlatform()

UserInputService.LastInputTypeChanged:Connect(function(lastInputType)
	if lastInputType == Enum.UserInputType.Touch then
		Player:SetAttribute("Platform", "Mobile")
	elseif string.find(lastInputType.Name, "Gamepad") then
		Player:SetAttribute("Platform", "Console")
	elseif lastInputType == Enum.UserInputType.Keyboard or string.find(lastInputType.Name, "Mouse") then
		Player:SetAttribute("Platform", "PC")
	end
end)

UserInputService.GamepadConnected:Connect(function()
	Player:SetAttribute("Platform", "Console")
end)

UserInputService.GamepadDisconnected:Connect(function()
	if not GuiService:IsTenFootInterface() then
		Player:SetAttribute("Platform", "PC")
	end
end)
5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.