Animation Doesn't Play

I was trying to play an animation using the UserInputService. Does anyone know why this might not work? It prints fine, just doesn’t play the animation. No Errors in the output.

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animation = humanoid:LoadAnimation(script.Parent.Animation)

	UIS.InputBegan:Connect(function(input, isTyping)
				if isTyping then
					return
			elseif input.KeyCode == Enum.KeyCode.E then
		print("yo")
		animation:Play()
				end		
		end)

image

Try using humanoid:WaitForChild("Animator"):LoadAnimation(...)

Just tried this out, and it doesn’t seem to make a difference.

Perhaps try this?

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = humanoid:LoadAnimation(script.Parent.Animation)
print("Character found")

UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then
		return

	elseif input.KeyCode == Enum.KeyCode.E then
		print("yo")
		animation:Play()
	end		
end)

He said it prints fine. I don’t think adding a check before print("yo") is going to make a difference.

Well it’s probably who exactly owned the Animation then

@zuoec Did you create the animation? If you didn’t, you have to create one yourself if you want the animation to play properly