Crouch Animation issues

Hello due to roblox switching up some stuff in the animations and stuff i dont know how to make the player crouch whenever i click C.

And yes i’ve looked on the internet, i could only find older versions.

Here is my script:

local animID = 16211272469
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Humanoid = player.Character:FindFirstChild("Humanoid")
local activated = false
local UIS = game:GetService("UserInputService")
local Animator = player.Character:FindFirstChild("Humanoid").Animator

local AnimationTrack = Animator:LoadAnimation(animID)


UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C and activated == false then
		AnimationTrack:Play()
		
	elseif input.KeyCode == Enum.KeyCode.C and activated == true then
		AnimationTrack:Stop()
	
	end
end)
2 Likes

The code is correct, if you want it to be toggleable rather than holding C. What’s missing here is the activated variable not changing. When you play the animation set activated to true, when you stop the animation set it to false.

if input.KeyCode == Enum.KeyCode.C and activated == false then
		AnimationTrack:Play()
		activated = true
	elseif input.KeyCode == Enum.KeyCode.C and activated == true then
		AnimationTrack:Stop()
	    activated = false
	end
1 Like

Thank you I will test this out right away!

The code is correct? Cuz nothing happens when i click C. I dont get any errors in the output either.

Well the code seems indeed correct, especially since you said it doesn’t throw any errors. If it doesn’t work then there’s a few possibilities, the main one I can think of is you don’t own the animation. To check if the code is running at all, add a print inside InputBegan. If you see the text printed in the output then you know the code is really running

Code does not seem to work. Tried adding a print(“works”) function to our InputBegan function. Nothing. No output print thing.

Gonna try to rewrite the code in perhaps a serverscript instead.

Very weird. So you believe the whole code isn’t running at all?
I’m guessing it’s a local script, where did you put the script in the game?

Is it not working completely or is it just buggy?

Also is the animation looped? (you can make it looped by opening the roblox animator and clicking the rotating button thing)

Don’t forgot to make it so that the UIS also has an if statement that says: if user is typing/has chat open then break - otherwise the user might accidently type c and crouch because of it.

1 Like

Is the animation yours? You can not use animations unless you published them, or to a group in which you have permissions.

I did publish it under my group. I made it myself aswell.

StarterCharacterScripts is where i placed the local script

Change Animator, you don’t need thtat. Just do humanoid:LoadAnimation(). You may need to use the rbxassetid://00000 instead of just the ID

Actually, you can’t pass animID to LoadAnimation. It needs to be an animation object.

local animID = 'rbxassetid://16211272469'
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Humanoid = player.CharacterAdded:Wait():FindFirstChild("Humanoid")
local activated = false
local UIS = game:GetService("UserInputService")

local animation = Instance.new("Animation")

animation.AnimationId = animID

local AnimationTrack = Humanoid:LoadAnimation(animation)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		activated = not activated
		print(activated)
		return activated and AnimationTrack:Play() or AnimationTrack:Stop()
	end
end)



Yeah I tried that too. Then I went on their documentation and its saying that :LoadAnimation() is deprecated.

But I can try it again, if you want me to.

The script I sent you works. Just replae the animID.

I haven’t tested it yet, but before I do. Does it matter that the character isnt touching the grid below?

Because I’ve tried moving the torso but the grid seems to move aswell.