How do I check when the player is attempting to move?

I’m attempting to make custom movement, but can’t find the event that fires when they try to move.

I’m aware that I can use UserInputService to detect when the W, A, S, and D keys are pressed but I want to make it work for all devices. I’ve searched through UserInputService but have come up dry.

I’m assuming (and hoping) there’s a universal function that detects when the player tries to move on all devices, like UserInputService.JumpRequest, but if there’s not how would I detect when the player tries to move on mobile and console?

edit: I’m not trying to check if the player is currently moving, or what direction they’re moving. I’m trying to create my own movement system and need to check when the player tries to move.

2 Likes

When you mean by checking the player if they are attempting to move, do you mean checking the player if they are currently moving?

No, sorry I should’ve clarified that. I’m disabling their movement and trying to check when they try to move with the touch pad or joystick.

So like you basically don’t want both PC and Mobile players to move, correct?

Yes, but I want to see when they attempt to.

Can’t you just disable movement at all?

So like, you basically want the players to stop their movement but also see if they try moving?

He is trying to make his own movement system so he wants to disable the default one.

Exactly, I can already just stop them from walking and jumping with the regular movement system by just setting walkspeed and jumppower to 0 (or just deleting the humanoid), but I don’t know how to check when they try moving

Well, for the gamepad you can use the IsGamepadButtonDown method in UserInputService and for mobile, you can use TouchSwipe.

Nvm, I have a better solution, use the property MoveDirection of the Humanoid, if a player tries to move, this property’s magnitude will be greater than 0. You can use the following code to check when a player tries to move:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.Character:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")

if not Humanoid then
    return
end

while task.wait() do
    if Humanoid.MoveDirection.Magnitude > 0 then
        print("Player is trying to move!")
    end
end)

The code should be in a LocalScript inside of StarterCharacterScripts.

1 Like

You can replace the while loop for RenderStepped or another event in RunService.

Oh I had no idea MoveDirection worked if the player wasn’t actually moving, but this is exactly what I was looking for, tysm!

1 Like

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