Check Player's platform (Mobile, Console, or PC)

I’m trying to check the player’s platform (mobile, console, or PC) to make buttons visible for mobile only, but I’ve run into a problem in which it shows the player is on mobile when tested on studio, but when tested on a real phone, it doesn’t work and prints “Computer” instead of “Mobile”. Please help me, provide another proficient and best way/method to obtain the player’s platform, if applicable/possible.

Here is my script:

function PlatformService.Client:GetPlatform(player)
	if not player then warn("No player provided!") return end
	
	local GuiService = game:GetService("StarterGui")
	local UserInputService = game:GetService("UserInputService")
		
	local IsMobile = UserInputService.TouchEnabled
	local IsConsole = UserInputService.GamepadEnabled
	local IsComputer = UserInputService.KeyboardEnabled
	
	if IsMobile then
		print("Mobile!")
		return "Mobile"
	elseif IsConsole then
		print("Console")
		return "Console"
	elseif IsComputer then
		print("Computer")
		return "Computer"
	end
end

Thanks for your time.
Note: I’m using the Knit framework but that won’t affect it anyways because the scripts works just fine overall, and I’ve tested it on studio tho.

1 Like

Someone help me please, I’m still trying to find a solution for this.

Resolved. [Was knit’s problem overall]

So if I needed to do the same, your above script worked perfectly without changes ?

I wouldn’t recommend getting the platform like this.

It has a few issues e.g. what if the player is using a touch screen laptop with a gamepad connected? Your code wouldn’t be able to handle this because IsMobile, IsConsole and IsComputer would resolve to true.

You’re better off using UserInputService’s GetLastInputType() method and LastInputTypeChanged event to derive the last used input and then varying the visibility of the buttons if the user is using touch input.

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