You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
make this device script checker work
What is the issue? Include screenshots / videos if possible!
it appear on pc eventho the users device are on mobile
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
tried usingai and discord helper
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that itâs easier for people to help you!
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function checkDevice()
local inputTypeString
if UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
inputTypeString = "PCđ„ïž"
elseif UserInputService.TouchEnabled then
inputTypeString = "Phoneđ±"
elseif UserInputService.GamepadEnabled then
inputTypeString = "Consoleđź"
end
txt = "Device: " .. inputTypeString
end
checkDevice()```
KeyboardEnabled has the potential to appear enabled to mobile/Xbox users because they can also have âkeyboardsâ (But not necessarily in the physical sense like in a PC) used for typing in chat and whatnot.
Also, there isnât a built in way to find what device a user is on so you have to resort to lots of hacky if statements but hopefully this should help, its the best I could find.
(Edit: I also found this other one which also seems to work)
I have an old code that works fine, am planned to remake it one day since its ugly imo. But it works
Client Sided:
local replicatedStorage = game:GetService("ReplicatedStorage")
local guiService = game:GetService("GuiService")
local UIS = game:GetService("UserInputService")
local function getPlatform()
if guiService:IsTenFootInterface() then
return "Console"
elseif UIS.TouchEnabled and not UIS.MouseEnabled then
return "Mobile"
else
return "Desktop"
end
end
local platform = getPlatform()
print(platform)
game.ReplicatedStorage.SetNametagIcon:FireServer(platform)
ServerSided:
local OverheadService = {
Templates = script:FindFirstChild("RankUI"),
Configuration = require(script:FindFirstChild('Configuration'))
}
function OverheadService:SetIconImage(ui, platform)
local Icon = ui.PlatformFrame.Icon
if platform == "Mobile" then
Icon.Image = 'rbxassetid://14188613808' -- Phone UI
elseif platform == "Console" then
Icon.Image = 'rbxassetid://14188383923' -- Console UI
elseif platform == "Desktop" then
Icon.Image = 'rbxassetid://13539002441' -- PC UI
end
end
game.ReplicatedStorage.SetNametagIcon.OnServerEvent:Connect(function(player, platform)
local character = player.Character
if character then
OverheadService:SetIconImage(character:WaitForChild("RankUI"), platform)
end
end)
In one of Roblox Template, you have a system that can likely help you.
-- We assume that InputCategory is a table.
-- Return an InputCategory based on the UserInputType
function ActionManager._getCategoryOfInputType(inputType: Enum.UserInputType)
if string.find(inputType.Name, "Gamepad") then
return InputCategory.Gamepad -- xbox/ps4
elseif inputType == Enum.UserInputType.Keyboard or string.find(inputType.Name, "Mouse") then
return InputCategory.KeyboardAndMouse -- pc/or mobile with keyboard and a mouse
elseif inputType == Enum.UserInputType.Touch then
return InputCategory.Touch -- mobile
else
return InputCategory.Unknown -- not defined
end
end
The script is in Platformer template in ReplicatedStorage.Utility.ActionManager.