My Platform Detector treats Mobile as Desktop

I have a module that checks on the platform the player is currently using. But, under mysterious circumstances, the module detects mobile as PC, which disabling all mobile functions

local UserInputService = game:GetService("UserInputService")

--[[return function()
	if UserInputService.GamepadEnabled then
		return "Console"
	else
		if UserInputService.TouchEnabled then
			if UserInputService.MouseEnabled and UserInputService.KeyboardEnabled then
				return "Desktop"
			else
				return "Mobile"
			end
		else
			return "Desktop"
		end
	end
end]]

return function()
	if UserInputService.GamepadEnabled then
		return "Console"
	elseif UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
		return "Mobile"
	else
		return "Desktop"
	end
end

(from my game Muffin Assault. Pay attention to “platform” on top left)

From my discord server, some people believed that Roblox chat was the cause of this. Still, I’m not certain about this. So are there any other causes that made this happen?

1 Like

That sounds somewhat likely. Your code might be detecting that the keyboard is the one enabled due to the user being in chat.
Perhaps try checking if the user is in chat and making sure they aren’t before you return the result?

2 Likes

Yeah, that seems to be like that. I have looked on another thread about the same issue. Unfortunately, there’s still no solution for it…

1 Like

Actually, sort of a hacky solution, but you could perhaps try disabling chat when the player first joins, and only enabling it again when you finish checking for the device.
(Might not work if the glitch would also happen if you use the mobile keyboard outside of the game)

Also, assuming this bug doesn’t happen with ContextActionService, you could also perhaps try creating a button like that, and checking wether or not it exists/is visible to determine if the device is mobile or not. (And then get rid of the button so it doesn’t block anything)

ContextActionService would do so, but I have already found a workaround to resolve this issue. By simply adding _G variable for the initial platform. And of course, it seems to work well, and no recent platform bug reports are made

2 Likes

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