How can I detect when people of different devices walk by pressing or holding something?

As you read from the title, I need to know how I can detect if someone from a different device that isn’t on computer such as xbox and mobile walk, obviously I need their keycode equivalents such as KeyCode.W if they walk forward, KeyCode.S if backwards etc… Any way to do that?

1 Like

Oh noes I put this on the wrong category on accident, how do I change it

You cant detect if a User is on a certain Device, but you can detect the Inputs they are using determine the Device, with this post as an example.

If you are just looking for How they made an input, look into UserInputType, which is a list of Inputs that the Client can make.

Edit the Topic, It shows you what Category its on, and from there you can change it.

1 Like

There is a pencil button next to the topic’s title. Use that.

1 Like

Edit the headline to change the category.

1 Like

Yeah but for example if someone is on mobile I need to detect if they’re trying to walk forward, backwards, jump etc…

You can use ContextActionService. ContextActionService is useful for different devices people may be using. It may seem complicated at first, but the more you get familiar with it, it’ll be really easy to understand!

local ContextActionService = game:GetService("ContextActionService")

local honkSound = Instance.new("Sound", workspace)
honkSound.SoundId = "rbxassetid://9120386436"

local function handleAction(actionName, inputState, inputObject: InputObject)
	if actionName == "HonkHorn" then
		if inputState == Enum.UserInputState.Begin then
			print(inputObject.UserInputType.Name)
			honkSound:Play()
		end
	end
end

workspace.ChildAdded:Connect(function(Child) -- When a child is added to the workspace, the player can now honk the horn by pressing H or the A button on an xBox controller to make this sound play.
	print(Child.Name.." was added.")
	ContextActionService:BindAction("HonkHorn", handleAction, true, Enum.KeyCode.H, Enum.KeyCode.ButtonA)
end)

workspace.ChildRemoved:Connect(function(Child) -- When a child is removed from the workspace, the player can no longer press H or the A button on an xBox to make this sound play.
	print(Child.Name.." was removed.")
	ContextActionService:UnbindAction("HonkHorn")
end)

If the player is on mobile, the third parameter is set to true so that the player can instead press a button to make the sound play.

(This only works in a LocalScript by the way.)

You can use Humanoid.MoveDirection

And HumanoidStateType to detect falling/jumping/swimming etc.

That’s not what I want, and cannot use it, the character I will be using won’t have a humanoid.

I don’t see how this can be useful to detect where the person is trying to walk

Then you would have to use Enum.UserInputType

Mobile:
Enum.UserInputType.Touch

There was another topic on that here although you would probaby need to modify this.

Gamepad/XBOX:
Enum.UserInputType.Gamepad1 and Enum.KeyCode.Thumbstick1

1 Like

Sorry. I mistook this for something else. What @lgotanintendoswitch said is what you’re looking for then.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.Keyboard then
		print("Player is using a PC.")
	elseif Input.UserInputType == Enum.UserInputType.Touch then
		print("Player is using a mobile device.")
	end
end)

This only works in a LocalScript! Of course, you can replace the print()s with the code that you’d like to add.