Reliable way of knowing if a player is on a computer?

Hey, so for my game, I added smooth camera animations to point where your mouse is looking. However, this looks undesirable on mobile, as when ever I tap a button the camera immediately changes its angle, and it looks kind of bad…and obviously console wouldn’t be any better, so I figured I would just disable the camera animations entirely for those platforms.

However, I wasn’t sure how I should go about figuring out if the player is on a PC or not. I know I can use the :IsTenFootInterface() method to determine if they’re on console, but I can’t really think of a way to know if they’re either on or not on PC. (I’ve heard its bad practice determining if it’s a touch enabled device, because touch laptops are a thing.)

Any advice is appreciated, thanks!

2 Likes

Funny thing is I’m currently on a touch-screen laptop.

Anyways, there is a way to check if someone’s on a PC, by checking if they have a keyboard:

local pc = game:GetService("UserInputService").KeyboardEnabled

if pc then

    print("wow y'all I'm on a PC")

end

Read more here:

This should work most if not all the time because I’ve never heard of phones/consoles that can connect a keyboard, but then again I think that TouchEnabled and GamepadEnabled would take higher priority.

2 Likes

I would use MouseEnabled or a combination of both MouseEnabled and KeyboardEnabled. Because iPhones, Android, and Xbox can actually use keyboard and mouse (although I’m not sure if it works with Roblox on those devices) and I think the newest iPad comes with a keyboard.

1 Like

You could try doing

local uis = game:GetService("UserInputService")
if uis.KeyboardEnabled then
   if not uis.TouchEnabled and not uis.GamepadEnabled then
      print("on pc")
   end
   if uis.GamepadEnabled then
      print("on gamepad")
   end
   if uis.TouchEnabled and not uis.GamepadEnabled and not uis.KeyboardEnabled then
      print("on mobile")
   end
end

(I didnt test this out so i may be wrong here)

2 Likes