So i need to verify with a script/local spript if it works
Each player's character model has a Humanoid
which controls how the player's character moves and stuff like that. There's an event you can use called Running
which triggers when the player starts walking/running:
-- Note: This is a server script game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) char.Humanoid.Running:Connect(function(speed) if speed > 0 then print("Humanoid is running at " .. speed) else print("Player has stopped running") end end) end) end)
The speed argument is the WalkSpeed of the player. While I was testing this event, I discovered that when the player goes from running to standing still, the event reads their current speed as 0.
If you need to check if the player is walking/running instantaneously without using an event, you can check the MoveDirection
property which returns a unit vector that describes the direction the player is moving in:
-- humanoid argument is a player's Humanoid function isRunning(humanoid) return (humanoid.MoveDirection ~= Vector3.new(0, 0, 0)) end
The condition inside the parentheses only checks if the player is running since Vector3.new(0, 0, 0)
is the value of MoveDirection
when the player is not moving. When true
is returned by the function, it means the player is moving. When false
is returned by the function, it means the player is not moving.
I hope this answers your question :)