The title is pretty self explanatory, how would I go about detecting whether the player is on computer, mobile or console (ps4/xbox).
How would they play on ps4? I didn’t think that was possible.
You can use UserInputService to do that (properties such as KeyboardEnabled, GamepadEnabled, TouchEnabled etc).
Like this using a local script:
local uis = game:GetService("UserInputService")
if uis.KeyboardEnabled == true then
print("Player is on pc")
elseif uis.GamepadEnabled == true then
print("Player is on console")
end
GamepadEnabled can work on both console and PC platforms, KeyboardEnabled can also potentially be triggered on PC and xbox and tablets due to those platforms supporting keyboards as an input source. Purely relying on TouchEnabled for touch-screen devices can potentially be triggered by non-mobile devices, like touchscreen laptops/2-in-1 devices.
A better solution would be to do something such as this in a LocalScript, and optimizing accordingly:
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled then -- This can happen because of touch-enabled devices potentially other than phones, such as laptops with touch screens.
print("User is on a touch-enabled device")
elseif GuiService:IsTenFootInterface() then -- this will only happen on console, since the check involves a specific version of Roblox's UI only on consoles.
print("User is on console")
end
1 Like