Is this a good way to get the player device

Of all ways to get a player’s device, is this an alright way to do it?

function playerModule.getPlayerDevice()
	if UserInputService.KeyboardEnabled and not UserInputService.TouchEnabled then
		return "pc"
	elseif UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled then
		return "mobile"
	end 
end
4 Likes

For people such as me with touch screen computers, your function would return nil. Same thing as well for controller players.

A better approach is to use the players preferred input.

https://create.roblox.com/docs/reference/engine/classes/UserInputService#PreferredInput

This will tell you what the last input used by the user was/take an educated guess if no inputs have been sent yet.

I as a user could connect a mouse and keyboard to my phone for example. The roblox client supports this. Many games do as well.

3 Likes

some laptops have touch enabled or a mobile or tablet can have a keyboard connect, you shouldnt say its a pc just because it has no touch, you should make games for each and if you really wanna know, id suggest going with this method and checking for resolution, typically lower resolution means mobile and also ofcourse check documentation

1 Like