I got these blocks of code from other threads and tried to make it so an image of the device the player is currently playing on will appear. But I joined the game on my phone and it shows the image of the monitor (PC) and prints “PC” and should print “Mobile” and show a phone image in the dev console. Any help is appreciated thanks
local Players = game:GetService("Players")
local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
function getplatform()
if (GuiService:IsTenFootInterface()) then
NameTagClone.Frame.Console.Visible = true
print("Console")
return "Console"
elseif (UserInputService.TouchEnabled and not UserInputService.MouseEnabled) then
local DeviceSize = workspace.CurrentCamera.ViewportSize;
if ( DeviceSize.Y > 600 ) then
NameTagClone.Frame.Tablet.Visible = true
print("Tablet")
return "Mobile (tablet)"
else
NameTagClone.Frame.Mobile.Visible = true
print("Mobile")
return "Mobile (phone)"
end
else
NameTagClone.Frame.PC.Visible = true
print("PC")
return "Desktop"
end
end
local function CharacterAdded(char)
--Character added code VVV
getplatform()
end
local function PlayerAdded(player)
player.CharacterAdded:Connect(CharacterAdded)
local char = player.Character
if char then
CharacterAdded(char)
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)
for i,v in pairs(game.Players:GetPlayers()) do
PlayerAdded(v)
end
I think its to see if it’s not just a laptop with a touchscreen screen to make sure if it’s a phone/tablet but just assumption since that was mentioned in the original post of that function
What I do in my games is this simple check in a Local Script under StarterPlayer/StarterPlayerScripts
local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled then
print("Is on mobile!")
elseif UserInputService.GamepadEnabled then
print("Is on Xbox!")
else
print("Is on PC")
end
Okay thank you both for letting me know this. I did not realize that but now I will have a new thing to check my code when it isn’t working to see if it works only on a client or server script.