Is there anyway to tell if a person is on an Xbox or a PS4/PS5?

  1. What do you want to achieve? Keep it simple and clear! I am trying to differentiate if the device is a xbox or PS4/PS5

  2. What is the issue? I don’t or know any possible way to check if its an Xbox or PS4/PS5

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I did but all of them just check for Xbox because the PS version is new.

16 Likes

In order to do this you will need a local script. You will have to use UserInputSerice.GamepadEnabled. it will return a boolean value. If the value will be True it will mean that the player is on Xbox or Playstation!

5 Likes

The OP is asking regarding how you’d differentiate between Xbox and PS4. GamepadEnabled doesn’t help

7 Likes

Not only does this not answer the OP’s question, it’s also incorrect. GamepadEnabled will return true for any platform, as long as there’s a plugged in controller. Even mobile.

And answering OP’s post, at the moment I think it’s impossible. You should be designing for a type of platform, not for specific platforms themselves, according to Roblox.

7 Likes

Thanks for trying to help anyways

4 Likes

my only recommendation would be to let users choose what they’re using
some games like bus stop simulator let the user choose their device

can’t think of an example but i’ve seen games that detect that you’re using mobile but ask you to pick ipad or iphone so the game can optimise itself to be suited for that device

6 Likes

The closest we have so far is GuiService:IsTenFootInterface() which will only return true for console. Unfortunately, there is not a way to determine what console directly.

You can also use UserInputService:GetImageForKeyCode(keyCode) to get the image for a button for whatever gamepad is currently plugged in (I don’t know how it decides which one to use). So…technically…you could figure out which image corresponds to the Xbox “A” button and which one corresponds to the PlayStation “X” button, and use that to decide. But that seems a bit of a hacky workaround.

10 Likes

It’s a genius workaround, but wouldn’t it be possible (although tricky) to connect an Xbox controller to a PlayStation or vice versa via Bluetooth and then trick the function into giving the wrong key code?

1 Like

Instead of criticizing other suggestions, could you give your own one? I think that’s what we all are waiting here for in the end.

2 Likes

How? I’m just saying that this feature is not 100% reliable, and as I’ve mentioned earlier in this thread, there is no official way to determine the player’s console (yet).

1 Like

You can use UserInputService:GetStringForKeyCode(keyCodeInput).

For example:

  • On Xbox, pressing the ButtonA KeyCode would return ButtonA. But, pressing the ButtonA KeyCode on PS4/PS5 would return ButtonCross.

Here is my current implementation of a input system. (click)

local userInputService = game:GetService("UserInputService")
local InputTypeChangedRE = game.Workspace.RemoteEventsFolder.Inputs.InputTypeChanged

---

local UserInputTypeSystemModule = {

	gamepadTypeFromNewestInput = "none",
	inputTypeThePlayerIsUsing = "KeyboardAndMouse", --keyboard mouse is default
	gamepadType = "none", -- "none" by default. Can be "Xbox" or "PlayStation"

}

local mouseInputType = {
		Enum.UserInputType.MouseButton1,
		Enum.UserInputType.MouseButton2,
		Enum.UserInputType.MouseButton3,
		Enum.UserInputType.MouseMovement, 
		Enum.UserInputType.MouseWheel	
}

local GamepadInputsList = {
	Enum.KeyCode.ButtonA,
	Enum.KeyCode.ButtonB,
	Enum.KeyCode.ButtonX,
	Enum.KeyCode.ButtonY,

	Enum.KeyCode.ButtonL1,
	Enum.KeyCode.ButtonL2,
	Enum.KeyCode.ButtonL3,

	Enum.KeyCode.ButtonR1,
	Enum.KeyCode.ButtonR2,
	Enum.KeyCode.ButtonR3,

	Enum.KeyCode.ButtonStart,
	Enum.KeyCode.ButtonSelect,
	
	--

	Enum.KeyCode.DPadUp,
	Enum.KeyCode.DPadDown,
	Enum.KeyCode.DPadLeft,
	Enum.KeyCode.DPadRight,
	
	Enum.KeyCode.Thumbstick1,
	Enum.KeyCode.Thumbstick2,


}

local mobileInputType = Enum.UserInputType.Touch

---


local Xbox_ReturnValues_List = {
	
	"ButtonA", -- KeyCode.ButtonA
	"ButtonB", -- KeyCode.ButtonB
	"ButtonX", -- KeyCode.ButtonX
	"ButtonY", -- KeyCode.ButtonY
	"ButtonLB", -- KeyCode.ButtonL1
	"ButtonLT", -- KeyCode.ButtonL2
	"ButtonLS", -- KeyCode.ButtonL3
	"ButtonRB", -- KeyCode.ButtonR1
	"ButtonRT", -- KeyCode.ButtonR2
	"ButtonRS", -- KeyCode.ButtonR3
	"ButtonStart", -- KeyCode.ButtonStart
	"ButtonSelect", -- KeyCode.ButtonSelect 
	
}

local PlayStation_ReturnValues_List = {
	
	"ButtonCross", -- KeyCode.ButtonA
	"ButtonCircle", -- KeyCode.ButtonB
	"ButtonSquare", -- KeyCode.ButtonX
	"ButtonTriangle", -- KeyCode.ButtonY
	"ButtonL1", -- KeyCode.ButtonL1
	"ButtonL2", -- KeyCode.ButtonL2
	"ButtonL3", -- KeyCode.ButtonL3
	"ButtonR1", -- KeyCode.ButtonR1
	"ButtonR2", -- KeyCode.ButtonR2
	"ButtonR3", -- KeyCode.ButtonR3
	"ButtonOptions", -- KeyCode.ButtonStart
	
	"ButtonTouchpad", -- KeyCode.ButtonSelect 
	"ButtonShare", -- KeyCode.ButtonSelect 

}

-- Note: Directional inputs have the same return value. This means, if a player presses a d-pad input, then the code knows it's a gamepad, but it doesn't know what type of gamepad. (PlayStation or Xbox, not sure.) 

---

userInputService.InputBegan:Connect(function(input)
	
	--print(input.KeyCode)
	
	-- Keyboard & Mouse Input: --
	if input.UserInputType == Enum.UserInputType.Keyboard then -- Keyboard inputs --
		if UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Gamepad" or UserInputTypeSystemModule.inputTypeThePlayerIsUsing == "Touch" then
			print("New InputType detected: Keyboard and Mouse")
			UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
			InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
			userInputService.MouseIconEnabled = true
			script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
			return
		end
	end
	for i, mouseInputs in pairs (mouseInputType) do -- Mouse inputs --
		if input.UserInputType == mouseInputs  then
			if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "KeyboardAndMouse" then
				print("New InputType detected: Keyboard and Mouse")
				UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "KeyboardAndMouse"
				InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
				userInputService.MouseIconEnabled = true
				script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
				return
			end
		end
	end
	----
	
		
	-- Gamepad Input: --

	for i, gamepadInput in pairs (GamepadInputsList) do -- Controller button inputs --
		if input.KeyCode == gamepadInput  then 
									
			if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Gamepad" then
				print("New InputType detected: Gamepad")
				UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Gamepad"
				InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
				userInputService.MouseIconEnabled = false
				script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = false
			end
			
			local stringForKeyCodePressed = userInputService:GetStringForKeyCode(gamepadInput)
			
			for i, retunValue_Xbox in pairs(Xbox_ReturnValues_List) do
				if retunValue_Xbox == stringForKeyCodePressed then
					--print(retunValue_Xbox,stringForKeyCodePressed)
					UserInputTypeSystemModule.gamepadTypeFromNewestInput = "Xbox"
				end
			end
			
			for i, returnValue_PlayStation in pairs(PlayStation_ReturnValues_List) do
				if returnValue_PlayStation == stringForKeyCodePressed then
					--print(returnValue_PlayStation,stringForKeyCodePressed)
					UserInputTypeSystemModule.gamepadTypeFromNewestInput = "PlayStation"
				end
			end			
			
			if UserInputTypeSystemModule.gamepadTypeFromNewestInput ~= UserInputTypeSystemModule.gamepadType then
				-- player is now using a different type of gamepad than before
				
				UserInputTypeSystemModule.gamepadType = UserInputTypeSystemModule.gamepadTypeFromNewestInput
				InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)

				print(UserInputTypeSystemModule.gamepadType)
			end
					
		end
	end
	----
	
	
	-- Touchscreen input: --
	if input.UserInputType == Enum.UserInputType.Touch then
		if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Touch" then -- if not mobile/touch input already, make it.
			UserInputTypeSystemModule.gamepadTypeFromNewestInput = "none"
			print("New InputType detected: Touch")
			UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Touch"
			InputTypeChangedRE:FireServer(UserInputTypeSystemModule.inputTypeThePlayerIsUsing)
			script.Parent:WaitForChild("IngameUI").MobileButtons.Visible = true
			
			local JumpButton_Path = script.Parent:WaitForChild("TouchGui").TouchControlFrame:WaitForChild("JumpButton")
			JumpButton_Path.Position = UDim2.fromScale(0.845, 0.715)
			--JumpButton_Path.Size = UDim2.new(JumpButton_Path.Size.X*1.2,JumpButton_Path.Size.Y*1.2)
			
			local ToggleMobileButton_RemoteEvent = game.Workspace.RemoteEventsFolder.UI.ToggleMobileButtons
			ToggleMobileButton_RemoteEvent.OnClientEvent:Connect(function(whatButtonShouldBeToggled,toggleState)
				if whatButtonShouldBeToggled == "JumpButton" then
					if toggleState == false then
						JumpButton_Path.Visible = false
						--print("Mobile Jump button toggled OFF")
					elseif toggleState == true then
						JumpButton_Path.Visible = true
						--print("Mobile Jump button toggled ON")
					end
				end
			end)
			
			return
		end
	end
	----

end)

return UserInputTypeSystemModule



Here's a shorter version with Gamepad only stuff. (click)

local userInputService = game:GetService("UserInputService")

local UserInputTypeSystemModule = {

	gamepadTypeFromNewestInput = "none",
	inputTypeThePlayerIsUsing = "KeyboardAndMouse", --keyboard mouse is default
	gamepadType = "none", -- "none" by default. Can be "Xbox" or "PlayStation"

}

local GamepadInputsList = {
	Enum.KeyCode.ButtonA,
	Enum.KeyCode.ButtonB,
	Enum.KeyCode.ButtonX,
	Enum.KeyCode.ButtonY,

	Enum.KeyCode.ButtonL1,
	Enum.KeyCode.ButtonL2,
	Enum.KeyCode.ButtonL3,

	Enum.KeyCode.ButtonR1,
	Enum.KeyCode.ButtonR2,
	Enum.KeyCode.ButtonR3,

	Enum.KeyCode.ButtonStart,
	Enum.KeyCode.ButtonSelect,
	--
	
	Enum.KeyCode.DPadUp,
	Enum.KeyCode.DPadDown,
	Enum.KeyCode.DPadLeft,
	Enum.KeyCode.DPadRight,
	
	Enum.KeyCode.Thumbstick1,
	Enum.KeyCode.Thumbstick2,

}

local Xbox_ReturnValues_List = {
	
	"ButtonA", -- KeyCode.ButtonA
	"ButtonB", -- KeyCode.ButtonB
	"ButtonX", -- KeyCode.ButtonX
	"ButtonY", -- KeyCode.ButtonY
	"ButtonLB", -- KeyCode.ButtonL1
	"ButtonLT", -- KeyCode.ButtonL2
	"ButtonLS", -- KeyCode.ButtonL3
	"ButtonRB", -- KeyCode.ButtonR1
	"ButtonRT", -- KeyCode.ButtonR2
	"ButtonRS", -- KeyCode.ButtonR3
	"ButtonStart", -- KeyCode.ButtonStart
	"ButtonSelect", -- KeyCode.ButtonSelect 
	
}

local PlayStation_ReturnValues_List = {
	
	"ButtonCross", -- KeyCode.ButtonA
	"ButtonCircle", -- KeyCode.ButtonB
	"ButtonSquare", -- KeyCode.ButtonX
	"ButtonTriangle", -- KeyCode.ButtonY
	"ButtonL1", -- KeyCode.ButtonL1
	"ButtonL2", -- KeyCode.ButtonL2
	"ButtonL3", -- KeyCode.ButtonL3
	"ButtonR1", -- KeyCode.ButtonR1
	"ButtonR2", -- KeyCode.ButtonR2
	"ButtonR3", -- KeyCode.ButtonR3
	"ButtonOptions", -- KeyCode.ButtonStart
	
	"ButtonTouchpad", -- KeyCode.ButtonSelect 
	"ButtonShare", -- KeyCode.ButtonSelect 

}
-- Note: Directional inputs have the same return value. This means, if a player presses a d-pad input, then the code knows it's a gamepad, but it doesn't know what type of gamepad. (PlayStation or Xbox, not sure.) 

userInputService.InputBegan:Connect(function(input)
		
	-- Gamepad Input: --
	for i, gamepadInput in pairs (GamepadInputsList) do -- Controller button inputs --
		if input.KeyCode == gamepadInput  then 
									
			if UserInputTypeSystemModule.inputTypeThePlayerIsUsing ~= "Gamepad" then
				print("New InputType detected: Gamepad")
				UserInputTypeSystemModule.inputTypeThePlayerIsUsing = "Gamepad"
				userInputService.MouseIconEnabled = false
			end
			
			local stringForKeyCodePressed = userInputService:GetStringForKeyCode(gamepadInput)
			
			for i, retunValue_Xbox in pairs(Xbox_ReturnValues_List) do
				if retunValue_Xbox == stringForKeyCodePressed then
					--print(retunValue_Xbox,stringForKeyCodePressed)
					UserInputTypeSystemModule.gamepadTypeFromNewestInput = "Xbox"
				end
			end
			
			for i, returnValue_PlayStation in pairs(PlayStation_ReturnValues_List) do
				if returnValue_PlayStation == stringForKeyCodePressed then
					--print(returnValue_PlayStation,stringForKeyCodePressed)
					UserInputTypeSystemModule.gamepadTypeFromNewestInput = "PlayStation"
				end
			end			
			
			if UserInputTypeSystemModule.gamepadTypeFromNewestInput ~= UserInputTypeSystemModule.gamepadType then
				-- player is now using a different type of gamepad than before
				
				UserInputTypeSystemModule.gamepadType = UserInputTypeSystemModule.gamepadTypeFromNewestInput

				print(UserInputTypeSystemModule.gamepadType)
			end
					
		end
	end
	
	
end)

return UserInputTypeSystemModule


If you haven’t yet, I’d take a look at the following:

Gamepad APIs: Cross-Platform Button Support

14 Likes

Wouldnt it be best to put the proper button binds though, xbox and playstation use different icons for their controllers.

2 Likes
1 Like

you just proved my point, thanks.

That came off a bit rude

That is what I meant, and good thing Roblox does support this. And thanks for it, this will be useful for some of my projects, didnt know it existed.

4 Likes

Here is a simple script just to check the client if they are on a (Modile, Pc , Xbox, Ps4/Ps5)

let me know if you didn’t understand anything on it i will try my best to help

--// put this on a client script ofc //--

if not game:IsLoaded() then game.Loaded:Wait() end

function GetDevice()
	if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
		return "Mobile"
	elseif UserInputService.GamepadEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
		return "Gamepad"
	elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
		return "PC"
	end
end

if GetDevice() == "Gamepad" then
	--// Xbox, PS4/5 //--
elseif GetDevice() == "Mobile" then
	--// Mobile //--
elseif GetDevice() == "PC" then
	--/ PC //--
end
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.