Help with detecting the player's platform

So I’m trying to make a system that changes a GUI based on the player’s platform. Now I know that detecting the player’s platform is considered unreliable due to the fact that you can use a controller on a PC and you can use mobile controls on a touch screen laptop. However, for what I am using it for it doesn’t really matter. Do note I have tried this script in both a server and local script without any success and without any errors.

Here’s the script:

local platformimage = script.Parent

local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled
	and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then

	platformimage.Visible = true
	platformimage.Image = "rbxassetid://7742783698" 

end

if not UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled
	and UIS.GamepadEnabled and GuiService:IsTenFootInterface() then

	platformimage.Visible = true
	platformimage.Image = "rbxassetid://7742783698" 

end
local GuiService = game:GetService("GuiService")
local UIService = game:GetService("UserInputService")
local Platform

if GuiService:IsTenFootInterface() then
	Platform = "console"
elseif UIService.TouchEnabled and not UIService.MouseEnabled then
	if workspace.CurrentCamera.ViewportSize.Y > 600 then
		Platform = "tablet"
	else
		Platform = "phone"
	end
else
	Platform = "pc"
end

Try this code, let me know if it works.

2 Likes

I’m a bit of a scripting newbie so please don’t judge me too much, but does this go in a local or server script?

If it has to do with a GUI I suggest client-sided (a local script), what you and @zrax_rb used UserInputService is, a client-sided service. So it should be client-sidedly, I suggest if you do want to send information from client to server use RemoteEvents.

Edit: Please close the topic if you can by marking a post above as solution.

Sorry, was updating the code, it would be in a local script.

Alright, thanks for the information.