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.
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
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.