How to define is player on mobile or not?

So, I want to make some QoL difference of mobile from PC. But I don’t know how to do it by scripting like:

player.IsOnMobile():Connect(function())

Does that exist in roblox lua? Or how can I do this besides making it by manual interaction?
Any help is appreciated🙏!

2 Likes

Localscript:

local device
if game:GetService("UserInputService").MouseEnabled and game:GetService("UserInputService").KeyboardEnabled then
	device = 'Computer'
elseif game:GetService("UserInputService").TouchEnabled then
	device = 'Mobile'
end

You can pass device through a remoteevent or remotefunction if you want to use it on the server

3 Likes

Thank you a lot for the help and for taking time! Sorrowfully that we don’t have a desired property or event for that. I hope this is gonna work for my script🙏

4 Likes

What if someone with a touchscreen laptop / phone wants to play using their touchscreen while having a keyboard and a mouse?

Getting the last input would be a better idea.

3 Likes

thats complex and none really wants something complex as that. while yes, this can happen if the laptop has a touchscreen its really rare. i haven’t seen any laptops have so far a touchscreen except my friend’s which i just befriended a year ago.

3 Likes
I made this script in 5 minutes, so surely you wouldn't want to lose players for such a reason?
local UserInputService = game:GetService("UserInputService")

local input = {
	Enum.UserInputType.MouseButton1,
	Enum.UserInputType.MouseButton2,
	Enum.UserInputType.MouseButton3,
	Enum.UserInputType.MouseMovement,
	Enum.UserInputType.MouseWheel,
	Enum.UserInputType.Keyboard
}

local touch = Enum.UserInputType.Touch

local lastInput
local function inputChanged(lastInputType)
	if lastInput ~= input and table.find(input, lastInputType) then
		print("mouse and keyboard")
		lastInput = input
	elseif lastInput ~= touch and lastInputType == touch then
		print("touch")
		lastInput = touch
	end
end

UserInputService.LastInputTypeChanged:Connect(inputChanged)

I know many people who would play newer games if the developers simply made such easy adjustments to give them a better experience.

2 Likes

this… is a messy script. always getting the inputs(what if i want to check it again in another script?, i’ll have to repaste the whole thing, instead of doing that i could store the inputs elsewhere!) and the if statements… nasty, you would not lose players really, its based. and by complex i meant, you can just check if they have touch enabled than just doing all of that all of that, while yes, your method will ensure it, its not really necessary in my opinion as i dont think anyone uses touch screen on their laptops if the feature is in it, that may be me, but as a example my friends dont, so thats my opinion

1 Like

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