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
humanoid.Running:Connect(function(speed)
if speed > 0 and not Debounce then
Debounce = true
----code
else
Debounce = false
end
end)
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
Humanoid.Running:Connect(function(speed)
if speed > 0 then
Walking = true
else
Walking= false
end
end)
return function()
return Walking
end
end
Example:
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
wait()
if IsWalking() then
print("Walking!")
end
end
Ooh, my bad, I didn’t see that. I’m really tired right now. I don’t understand why that wouldn’t work though, any errors? And if you don’t mind, can you share your code?
It says in https://developer.roblox.com/, that it only fires after you jump or something like that. I tried it, as expected, the code in the statement is started after I jump.
(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.