I’m trying to make a button that can be pressed by mobile and pc, how would I do that?
basically this
if game.UserInputService.KeyboardEnabled then
print("Player has joined from a Pc")
end
if game.UserInputService.TouchEnabled then
print("Player has joined from a Phone")
end
The only way to detect if someone is on mobile or PC is to do something like this:
local UIS = game:GetService("UserInputService")
local TouchEnabled = false
UIS.TouchTap:Connect(function()
TouchEnabled = true
end)
The issue with this is that it will trigger if someone is using a laptop with a touchscreen.
What type of button are you trying to make? If it is a ScreenGui or SurfaceGui, then you can just use the MouseButton1Clicked event.
I mean when a button is pressed the function should happend to a pc and mobile. I’m sorry for making the title missleading
Touchscreen laptops exist, causing an issue.
local uis = game:GetService("UserInputService")
local device
if uis.TouchEnabled and not uis.KeyboardEnabled then
print("Player is on mobile")
device = "mobile"
elseif uis.KeyboardEnabled and not uis.TouchEnabled then
print("Player is on PC")
device = "computer"
else
print("Player is on mobile")
device = "mobile"
--better to assume they are mobile if not found
end
What do you mean? Do you want a function to happen differently to PC and mobile users? You could adapt the code, and store the device in a variable and check it from there.
I need a button that will work for mobile and pc because mousbutton1click will only work for pc
MouseButton1Click
fires on mobile as well, as well as MouseButton1Up
and MouseButton1Down
.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.