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)
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
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)
Essentially, all roblox animations (default) are set to core priority. Anything higher means that your animations gets priority over roblox animations.
Go to animation editor and hover over the three buttons:
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.
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?
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)
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)