Crouch Animation Not Functioning

Hello, I am currently learning how to animate and my C to Crouch animation is not working. I tried looking up YouTube videos and searching through the DevFourm, but I still cannot find an answer.

Everytime I press “C”, I revieve this error:

LoadAnimation is not a valid member of Animation "Workspace.matthewthekider.CrouchAni"

.

Local Script:

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

mouse.KeyDown:Connect(function(Key) 
	if Key == "c" then
		local Animation = Instance.new("Animation", player.Character)
		Animation.Name = 'CrouchAni'
		Animation.AnimationId = 7329699996
		local Crouch = Animation:LoadAnimation(Animation)
		Crouch:Play()
	end  
end)

Thank you in advance.

I think you meant to do Humanoid:LoadAnimation()

local player = game.Players.LocalPlayer
local mouse = player:GetMouse() 
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')

mouse.KeyDown:Connect(function(Key) 
	if Key.KeyCode == Enum.KeyCode.C then
		local Animation = Instance.new("Animation", Character)
		Animation.Name = 'CrouchAni'
		Animation.AnimationId = "rbxassetid://7329699996"
		local Crouch = Humanoid:LoadAnimation(Animation)
		Crouch:Play()
	end  
end)

Also you should be referencing the Key.KeyCode, not just the Key

Animation Instances don’t have a LoadAnimation function, but Humanoid/Animator Objects do

1 Like

Hmm, I do not get any error now and no animation plays.

Could you try again? I went ahead & fixed a couple of issues

Still, nothing seems to happen. Nothing in the output and no animation. I also added prints and the key isn’t being pressed.

Oh, that explains it

Why are you using the mouse.KeyDown Event? You should be using UserInputService’s InputBegan Event instead to detect whenever specific keys get pressed

Try this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse() 
local UIS = game:GetService("UserInputService")
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')

UIS.InputBegan:Connect(function(Key, Chatted)
    if Chatted then
        return
    end

	if Key.KeyCode == Enum.KeyCode.C then
		local Animation = Instance.new("Animation", Character)
		Animation.Name = 'CrouchAni'
		Animation.AnimationId = "rbxassetid://7329699996"
		local Crouch = Humanoid:LoadAnimation(Animation)
		Crouch:Play()
	end  
end)

Ohhh, you’re right.

“CrouchAni” becomes a child of the character each time C is pressed but it does not play when C is pressed. There are also no errors.

Is the animation priority higher than core?

Essentially, all roblox animations (default) are set to core priority. Anything higher means that your animations gets priority over roblox animations.

https://developer.roblox.com/en-us/api-reference/property/AnimationTrack/Priority

Priorities Types:

Core
Idle
Movement
Priority

I do not know what that means, how can I determine this?

Go to animation editor and hover over the three buttons:
image

Go to animation priority and click Idle or movement, or priority. Whichever, just not core.
Then export, and then on the bottom left, it should say “Export As” or something like that. And then replace your old animation with the new, fixed animation.

I think you meant Action

image

@TixFoil By default, whenever you upload ROBLOX animations via the Animation Editor, their Priority is set by Core (I think)

I exported a “new” animation with the priority set to “Action” and the animation still does not work.

Do you have an animation with a high priority I can use to just test to see if it works? It can be a free model, I just want to test it.

The thing is, for an animation to work in game (not studio), it needs to be owned by you. Also, what is your character you’ve animated? R6 or R15? And what’s the game avatar set to?

R15 and the game avatar is set to:

What type of character did you animate? R6 or R15.

R15
word word limit word limit

Oh wait, I just got an error. I tried moving the script under StarterPlayer.StarterPlayerScripts and I got this:

LoadAnimation requires the Humanoid object (matthewthekider.Humanoid) to be a descendant of the game object

Current script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse() 
local UIS = game:GetService("UserInputService")
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end

	if Key.KeyCode == Enum.KeyCode.C then
		local Animation = Instance.new("Animation", Character)
		Animation.Name = 'CrouchAni'
		Animation.AnimationId = "rbxassetid://7330023987"
		local Crouch = Humanoid:LoadAnimation(Animation) -- Error line
		Crouch:Play()
	end  
end)

Can you send the current script?

I just edited it in the previous message.

Try this

local player = game.Players.LocalPlayer
local mouse = player:GetMouse() 
local UIS = game:GetService("UserInputService")
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')

local Animation = Instance.new("Animation")
Animation.Name = 'CrouchAni'
Animation.AnimationId = "rbxassetid://7330023987"

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end

	if Key.KeyCode == Enum.KeyCode.C then
        Animation.Parent = Character

		local Crouch = Humanoid:LoadAnimation(Animation) -- Error line
		Crouch:Play()
	end  
end)