Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to detect a mobile device?

I want to detect a mobile device and enable the custom mobile GUI. The code I have right now is not working as it displays the PC GUI every time I play on mobile.

local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled
	and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
		script.Parent.Enabled = true -- MobileGUI located in StarterGui
else
		script.Parent.Parent.ZedsMarketPC.Enabled = true

end

Any help would be appreciated.

1 answer

Here's a guide

local userInputService = game:GetService("UserInputService")
 
if userInputService.TouchEnabled then
	print("The user's device has a touchscreen!")
else
	print("The user's device does not have a touchscreen!")
end

6 comments

0

I've used this code and added script.Parent.Enabled = true (for the MobileGUI) and script.Parent.Parent.PCGUI.Enabled = true but it still doesn't work?

0

It seems to always be enabling the PC GUI with no printed errors.

0

Try publishing it.

0

Also did you try printing/debugging it?

0

Weird - I tried printing and it's always printing 'The user's device does not have a touchscreen', even though I'm on mobile.

0

SOLVED. Had to enable GUI from PlayerGui instead of script.Parent.

This discussion is preserved as it was. New answers, comments, and votes are closed.