Crouch Animation

I made a Crouch Animation Script and the only thing thats missing is: When you stand still, the crouch animation keeps playing… How do I fix that?

My script: (feel free to edit and use it)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Animate 
local Humanoid = player.Character:FindFirstChild('Humanoid')

mouse.KeyDown:Connect(function(Key) 
    if Key == "c" then
    	Humanoid.WalkSpeed = 6 ---- change 6 to what speed you want
    	local Animation = Instance.new("Animation", player.Character)
    	Animation.AnimationId = "rbxassetid://6017867663"
    	Animate = Humanoid:LoadAnimation(Animation)
    	Animate:Play()
	end  
end)

mouse.KeyUp:Connect(function(Key)
    if Key == "c" then
    	Humanoid.WalkSpeed = 16
    	Animate:Stop()
	end
end)
1 Like

The solution would probably be to have 2 animations, an idle crouch and a moving one.

ok, but how do i check, if the character is moving or not?

This may not be an answer but is an further question.
Why are u using mouse instead of userinputservice or contextactionservice.

Read into this

Velocity would be a nice idea.
U can use humanoidrootpart.Velocity so if velocity was = 0 then player is idle else he’s moving

It’s a nice idea, but the velocity looks something like this:

7.0420072e-05, -0.000157290706, 4.29271931e-05
1 Like

that is irrelevant, if the player is standing still then velocity will be 0,0,0

How do I check, if the velocity is between two numbers?

you can check velocity.Magnitude or just check velocity.X = 0 and etc.

One step further, thanks!

But somehow the velocity of x is always between -1 and 1 how do i check if the current number is between these both?

You can do either

if x > -1 and x < 1 then
   -- stuff
end

or

if math.abs(x) < 1 then
   -- stuff
end
1 Like

just check this

if HumanoidRootPart.Velocity ~= Vector3.new(0,0,0) then

u can use velocity.Magnitude
that would return a single number. which would be really useful.
sorry i forgot to mention magnitude

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.