Animation not playing on key press

I am trying to play an animation when I press the letter Q; however, the animation is not playing, there are no errors presented. I have put in print statements to test if my code is running correctly and both statements go through. I do not know if I made a typo or something as I am still learning lua

My code is a local script inside the starterplayerscripts folder

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()


local wandAnimation = Instance.new("Animation")
wandAnimation.AnimationId = "rbxassetid://12725590286"

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q  then
		print("q was pressed")
		local LoadAnimation = Char.Humanoid:LoadAnimation(wandAnimation)
		LoadAnimation:Play()
		print("finished")
	end
end)


Solution for those viewing this thread in the future: Go to game settings and make sure that animations is NOT set to player choice and body type is set to whatever type you animated your rig in. Hope this helped you :smiley:

4 Likes

put it in startercharacterscripts and not starterplayerscripts

It is supposed to be the Humanoid’s Animator since Humanoid:LoadAnimation() is deprecated.

local LoadAnimation = Char.Humanoid.Animator:LoadAnimation(wandAnimation)

Sorry for the late reply, I have tried both of these solutions yet none of them work.

Here is what pops up in the console

The code worked just fine for me, did you make sure the ID was correct and if animation has the right priority?

I have it set to action? should I set it to something else?

Well I mean if you have it on the right priority (which you do) the only other thing that could be wrong is that the ID is wrong. I’m honestly not sure what else it would be.

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