I have seen this once many times here on DevForum before but it does not seem to work.
I am trying to seperate PC UI for mobile UI.
I have tried several scripts and they all dont seem to work.
Can someone help?
Edit:
New Problem
Here is the current script
local UserInputService = game:GetService("UserInputService")
function ReturnDevice()
if UserInputService.KeyboardEnabled then
script.Parent.Loading1_PC.Enabled = true
elseif UserInputService.GamepadEnabled then
print("No")
elseif UserInputService.KeyboardEnabled and UserInputService.TouchEnabled then
script.Parent.Loading1_PC.Enabled = true
elseif UserInputService.TouchEnabled then
script.Parent.Loading1.Enabled = true
else
return false
end
end
So the loading screen does not show but the LoadingScreen scripts work and both UI’s appear.
(There in separate ScreenGUI’s)
local UserInputService = game:GetService("UserInputService")
function ReturnDevice()
if UserInputService.KeyboardEnabled then
return "Keyboard"
elseif UserInputService.GamepadEnabled then
return "Gamepad"
elseif UserInputService.TouchEnabled then
return "Mobile"
else
return false
end
end
Your script does not work for a laptop with touchscreen.
local UserInputService = game:GetService("UserInputService")
function ReturnDevice()
if UserInputService.KeyboardEnabled then
script.Parent.Loading1_PC.Enabled = true
elseif UserInputService.GamepadEnabled then
print("No")
elseif UserInputService.TouchEnabled then
script.Parent.Loading1.Enabled = true
else
return false
end
end
Should I add another elseif statement saying if they have Keyborad and Touch?
local KeyboardEnabled = game:GetService("UserInputService").KeyboardEnabled
local AccelerometerEnabled = game:GetService("UserInputService").AccelerometerEnabled
local GyroscopeEnabled = game:GetService("UserInputService").GyroscopeEnabled
local GamepadEnabled = game:GetService("UserInputService").GamepadEnabled
local TouchEnabled = game:GetService("UserInputService").TouchEnabled
local IsTenFootInterface = game:GetService("GuiService"):IsTenFootInterface()
local Data = {
KeyboardEnabled,
AccelerometerEnabled,
GyroscopeEnabled,
GamepadEnabled,
TouchEnabled,
IsTenFootInterface
}
if Data == nil then return {"error",{"error"}} end
if #Data ~= 6 then return {"error",{"error"}} end
local Points={pc=0, mobile=0, tablet=0, console=0}
if Data[1] then -- Keyboard
Points.pc += 1
end
if Data[2] then -- Accelerometer
Points.mobile += 1
Points.tablet += 1
end
if Data[3] then -- Gyroscope
Points.console += 1
end
if Data[4] then -- Gamepad
Points.mobile += 1
Points.tablet += 1
end
if Data[5] then -- Touch
Points.console += 1
end
if Data[6] then -- IsTenFootInterface
Points.console = math.huge
end
local old = {"error", 0}
local others = {}
for i,v in pairs(Points) do
if v > old[2] then
old = {i, v}
end
end
for i,v in pairs(Points) do
if v == old[2] and i ~= old[1] then
table.insert(others, i)
end
end
local Platform = {old[1], others}
if #Platform[2] ~= 0 then
print("You are probably on: "..Platform[1].." or "..table.concat(Platform[2], " or "))
else
print("You are probably on: "..Platform[1])
end
if table.find(Platform[2], "pc") or Platform[1] == "pc" then
-- Give PC UI
elseif table.find(Platform[2], "mobile") or Platform[1] == "mobile" then
-- Give Mobile UI
end
I have modified it to be on the client only, put it in StarterPlayer → StarterPlayerScripts ; (As a localscript)
by tweaking I meant changing how many points a single determinant gives to be more accurate
It also seems like it detects mobile as console so maybe add points based on the size of the screen to differentiate between the two
local UserInputService = game:GetService("UserInputService")
function ReturnDevice()
if UserInputService.KeyboardEnabled then
script.Parent.Loading1_PC.Enabled = true
elseif UserInputService.GamepadEnabled then
print("No")
elseif UserInputService.TouchEnabled then
script.Parent.Loading1.Enabled = true
else
return false
end
end
But with a few Edits.
Where should I put it?
Make it so if they have Keyboard and Touchenabled that PC UI still shows. Like does and work in Lua?