Check if player is walking or not?

Yoinked some crouch script from a youtube tutorial and would like to konw: how do I make it so that if the player is crouched but isnt moving, the crouch animation will stop or freeze. How do I do it?

local uis = game:GetService(“UserInputService”)
local newanim = Instance.new(“Animation”)
newanim.AnimationId = “rbxassetid://6744589318”
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChildWhichIsA(“Humanoid”)
local animtrack = hum:LoadAnimation(newanim)
local cam = game.Workspace.CurrentCamera
local hrp = char:FindFirstChild(“HumanoidRootPart”)

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
cam.CameraSubject = hrp
animtrack:Play()
hum.WalkSpeed = 8
hum.JumpPower = 0
end
end)

uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
cam.CameraSubject = hum
animtrack:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
end
end)

1 Like

You would most likely need to check the Humanoid State. Humanoid | Roblox Creator Documentation will return the Humanoid’s current state, such as “Walking”, or “Idle” (not moving)

How would I exactly use it though, for this?

Something along these lines should help:

local Humanoid = -- Wherever your humanoid is

Humanoid.Running:Connect(function(speed)
    if speed > 0 then
        -- Player is running
    end
end)
1 Like

Check out Roblox’s handy dandy docs. [Humanoid | Roblox Creator Documentation] Scroll all the way to the bottom.

For easy explanation,
When the player presses C, make a debounce so that if they were to press it again, they would stop crouching.

Then in the function, listen to MoveDirection to detect whether they stopped or started to walk. Disconnect the function whenever they press it again, which would make them stop crouching.

i tried something like this, and it isnt working

if not hum:GetState() == Enum.HumanoidStateType.Running then

animtrack:AdjustSpeed(0)

else

animtrack:AdjustSpeed(1)

end

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

while wait(1) do
  if not (humanoid.MoveDirection.Magnitude <= 0) then
    print('you are walking and farting')
  end
end
1 Like

Did you reply to the wrong person on accident?

i replied to you as you were more active than the last guy.

I don’t want to be rude but that wasn’t what I suggested, which is why I assumed you replied to the wrong person on accident.

But that’s pretty much your answer right there

1 Like