Hey guys! I have been working on these door GUIs where you press the button that appears on screen to unlock the door. I have functionality for both PC (F-Key) and Xbox (X-Button) so far. The one issue is, I can’t figure out how to detect which platform the player is playing on, so I need to find a way to:
Detect the platform the player is currently on.
If the player is on that platform, put on screen which button they need to press.
My best bet would be to use the GuiService:IsTenFootInterface() function, as only Xbox users will have this set to true.
Example:
local UIS = game:GetService("UserInputService")
local GS = game:GetService("GuiService")
if GS:IsTenFootInterface() then
-- Xbox code
elseif not GS:IsTenFootInterface() and UIS.KeyboardEnabled then
-- PC code
end
The more I look into it, UIS.GamepadEnabled might be the better option. Since in this case the “X-Button Mode” should also apply to PC users with a controller, it seems more fit. Thanks though anyways, here’s a solution since you mentioning the API is how I found the answer.
Roblox doesn’t have any native ways to check the platform you’re using nor does they encourage that, but if you really need to check, then you can track the player’s input by using GetLastInputType and make that variable accessible to other scripts. You can then make configurations based on this.
You can use three identifiers: PC, mobile and console. For input types that you do not track, do nothing and use the last set value (e.g. for Focus, that’s not specific to a device, so don’t update the platform variable). This identifier will help you configure and decouple the work from other systems.
* I put mouse input under “do nothing” because a mouse is a completely separate input device. Roblox only provides you way to check input devices and what they’re sending, so we can’t make the assumption that a user is on PC just because they send mouse input.