How can i add a animation into this script

Essentially what we’re doing is creating a new “Animator” for your character by calling Humanoid:LoadAnimation(), then in your Input function we call LoadedAnimation:Play() to play it.

local CoolDown = true
local Key = "Z"

local Animation = script.Animation
local Humanoid = Character:WaitForChild("Humanoid")

local LoadedAnimation = Humanoid:LoadAnimation(Animation) 
-- do not put Animation in quotation marks, since it's a variable, not text

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	local KeyPressed = Input.KeyCode
	if KeyPressed == Enum.KeyCode[Key] and CoolDown and Character then
		CoolDown = false
		
		
		LoadedAnimation:Play()
		Remote:FireServer()


		wait(5)
		CoolDown = true 
	end
end)

Something like this should work, and as @NamyDev said be sure to put an Animation inside of your script, like this, then in “Properties” change the AnimationId to your id.

image

image

1 Like

Don’t use quite “” and do script.Animation

1 Like

Thanks :slight_smile: I am on mobile right now so hard to explain.

2 Likes

Ty for you all’s helps it finally solves the problem thx for the amount of time u guys spent here to help me, TYSMMMM!!!

Correction: DO NOT USE HUMANOID TO LOAD ANIMATIONS. IT IS DEPRECATED.

Instead, use Animator.

???
what do u mean

The default way to load Humanoid:LoadAnimation(), is deprecated. Animator is a child of the Humanoid and it’s a better alternative to load animation. So you should use Animator:LoadAnimation()

1 Like

Should i gave up, i spent few hours and solved this problem now i had a new problem

What’s the new problem? Create a new topic and talk about it so you can get more help.

i created a new one already lol, but no solutions yet

Ah yeah I read about that the other day, I never realised it was deprecated until recently.

I used LoadAnimation because I was demonstrating how you’d do it with that method (the method shown by the first reply)