How do you fire a function from input by a dynamic thumbstick?

Hello

Basically, I’m asking this for my friend (which does not have access on DevForum to post topics, yet)

Context: - I am trying to modify my fly script to allow for mobile inputs.

Problem: - I cannot get my function to fire when the thumbstick is used.

Attempted solution 1: - I tried using ContextActionService binding to Enum.PlayerActions.CharacterForward, CharacterBackward, etc. This is what I am using to detect WASD keyboard inputs, but it does not work for mobile devices (I’m guessing it won’t work for gamepads, ie xbox controllers, etc)

Attempted solution 2: - I tried to use UserInputService.InputBegan:Connect(function) . This didn’t fire when I used the emulator in studio.

Attempted solution 3: - I tried to use Humanoid.MoveDirection . This works for the x and z axis. However, it doesn’t update the y axis, which is required for a fly script.

Any advice/solutions you can give would be appreciated.

Hey so, first off, for the Attempted Solution 2, it would be UserInputService.InputBegan:Connect(function(input, GameProcessed) Second, you should detect if a player is playing in mobile or pc, then using a function like for example:
–Checking if player is on mobile or pc

local Mobile = UserInputService.TouchEnabled and not UserInputService.MouseEnabled

local Key
if Mobile then
Key = nil
else
Key = Enum.KeyCode.E
end

Also,
You should do .Activated Event for if Mobile and MouseButton1Click if the user is on PC, or maybe making like buttons, to move, like button.MouseButton1Down:Connect(function()

This is not an accurate way to check device type. There is no native way to check what device the player is using, only what kind of input they’ve sent from their client. There are multiple threads discussing this that you’re able to find on the DevForum.

If you want actual scalability, you can avoid doing all this in the first place and just make an action based on the type of input that was sent.

UserInputService.InputBegan:Connect(function (input, processed)
    if not processed then
        if (input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.E) or (input.UserInputType == Enum.UserInputType.TouchTap) then

(Note: the above would be better done by creating a dictionary where the input type or keycode is a key and the function is a value.)