UI Separation script for PC and Mobile Needed

Ya just looked at it some more it doesnt work at all.

So the loadingscreen doesnt pop up but for mobile and PC the scripts work

What does not work?
image

1 Like

No I am telling you about my script

I think your script won’t work for UI.

Wait a minute @SillyMeTimbers where should I put the script.

Right now its a Local Script in StarterGUI

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

1 Like

As local script or regular?

I think local right

Yeah it doesnt work.

I think we have to use

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.

  1. Where should I put it?
  2. Make it so if they have Keyboard and Touchenabled that PC UI still shows. Like does and work in Lua?

What do you mean it doesnt work, it works fine for me… this script is essentially the same thing

Please consider researching on the internet before asking, and the second question you asked should go in collabration, not script help.

Why should it go in collaboration?

I asked if it was possible to do that.

I literally said that and said I tried almost all the scripts.

Ok now I got this

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

I think you cant do game.StaterGUI. (Because I tried that already)

Someone told me you have to do like PlayerGUI or something but I cant find that and dont know how to do that.

(Its in StaterPlayer - StartingPlayerScripts as a Local Script)

Depending on your situation using the player’s input type isn’t beneficial. You can basically tell if someone is on a laptop or tablet/phone based off their ViewportSize in pixels. If Roblox’s API descriptions hold up GuiService | Roblox Creator Documentation can be used to identify console players.

I would less worry about the exact device a player is using a more focus on the characteristics of their device because over the past few years devices have been starting to cross boundaries as technology improves.

1 Like

I am not really conserd about console

Just more about PC and Mobile.

But thank You

How would I get the characteristics of a Mobile or PC device?

Update:

tried this it didn’t work

local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer 

function ReturnDevice()
	if UserInputService.KeyboardEnabled then
		plr.PlayerGui:WaitForChild("Loading1_PC").Enabled = true 
	elseif UserInputService.KeyboardEnabled and UserInputService.TouchEnabled then
		plr.PlayerGui:WaitForChild("Loading1_PC").Enabled = true 
	elseif UserInputService.TouchEnabled then
		plr.PlayerGui:WaitForChild("Loading1").Enabled = true 
	else
		return false
	end
end

You should check Cross-Platform Design | Roblox Creator Documentation out, it might help you, you can also try using this function to detect the last input type the player used: UserInputService | Roblox Creator Documentation

This is a basic function right here that does the job

local UserInputService = game:GetService("UserInputService")

local Mobile = false


coroutine.wrap(function()
	while wait(1) do
		Mobile = (UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled)
	end
end)();


-- The "UI" variable below just acts as if I have a ScreenGui and a PC / Mobile frame inside of it.
local UI = Mobile and Gui.Mobile or Gui.PC

Then after this you could create a BindableEvent that fires whenever mobile changes. After that you could connect a Update Interface function that changes to pc if mobile is false , and vice versa.

Hmm ok.
Where would you put this?
Btw I made 2 seperate ScreenGuis - 1 for mobile 1 for pc

Btw I edited the post so you all can see my current problems

What do you mean by

So the loading screen does not show but the LoadingScreen scripts work and both UI’s appear.

?

Its a loading screen

So if there on mobile the loading screen is enabled and everything else is invisible but after some time both the invisble stuff become visible.

Its like the UI wont show but the script is still working.