I know this sounds kinda dumb or something since it is probably easy to find out, but how would I find when the humanoid is walking? I used if Humanoid.MoveDirection.Magnitude > 0 but it was unreliable and when I turned a different direction, the code below the if statement starts again.
If you are wanting the code inside the if statement to only run once when the player runs then yes you can use a debounce:
local Debounce = false
if speed > 0 and not Debounce then
Debounce = true
Debounce = false
Btw, if you wanted to “use the event in an if statement” elsewhere easily, than inside the event, you can create a function to return whether or not the humanoid is walking, something like this
local function IsWalkingListner(Humanoid)
local Walking = false
if speed > 0 then
Walking = true
local Player = game.Players.LocalPlayer
local Character = game.Players.LocalPlayer.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local IsWalking = IsWalkingListner(Humanoid)
while true do
if IsWalking() then
(vel * Vector3.new(1, 0, 1)).Magnitude > threshold
or sqrt(vel.X*vel.X + vel.Z*vel.Z) > threshold
use vel = rootPart.Velocity - standingPart.Velocity if you want to account for any platforms they are currently standing on somewhat.
Otherwise, just vel = rootPart.Velocity should be good enough to detect if they are moving at all.
You can also check their Humanoid.MoveDirection which resets to <0,0,0> when there is no input from controllers / keyboard / etc.
All these are viable ways of detecting if they are walking or moving at all.