Combat Tool Idle Animation not working

Can someone send me something or explain to me how animations work. Cause I have no idea, I’ve looked at the wiki I’ve looked at tutorials on YouTube. I just can’t figure out on how to add animations to literally anything I’ve been stumped on this for a whole month now I can’t seem to figure out how to play a idle animation whenever the player equips the combat tool

1 Like

You need to create an Animation object with an AnimationId, then use the Humanoid to load an AnimationTrack using :LoadAnimation

Copied off of Code Samples in the Documentation.

local animation = Instance.new("Animation")
animation.AnimationId = "" -- Your animation ID

local animationTrack = Humanoid:LoadAnimation(animation)

Tool.Equipped:Connect(function()
	animationTrack:Play()
end)

Tool.Unequipped:Connect(function()
	animationTrack:Stop()
end)

Humanoid:LoadAnimation() is deprecated, the OP correctly used the Animator though I think Tool.AnimationFolder:WaitForChild("Idle")
should be moved into a variable and used in LoadAnimation() as such, also in the future please post the code in text OP, otherwise it makes it very hard to help you.

So how do i play the animation now?

Can you please first post the code as text

Oh Sorry

– Setup
local Tool = script.Parent

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild(“Humanoid”)

–Animations
local Animator = Humanoid:WaitForChild(“Animator”)

local Idle = Animator:LoadAnimation(Tool.AnimationFolder:WaitForChild(“Idle”))

Tool.Equipped:Connect(function()
Idle:Play()
end)

Tool.Unequipped:Connect(function()
Idle:Stop()
end)

I’ll make a non-deprecated version.

You need to add an Animator object, so we can use it to load animations instead of the Humanoid. This code does not detect if an Animator object already exists, though.

local animator = Instance.new("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "" -- Your animation ID

local animationTrack = animator:LoadAnimation(animation)

Tool.Equipped:Connect(function()
	animationTrack:Play()
end)

Tool.Unequipped:Connect(function()
	animationTrack:Stop()
end)

I’m getting an error saying Cannot load the AnimationClipProvider Service.

Whoops, my bad! When loading an animation using that object, it won’t work because the object is not part of anything. Also, I just noticed that the humanoid already has an Animator object, so you can use that instead.

local animator = Humanoid:WaitForChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "" -- Your animation ID

local animationTrack = animator:LoadAnimation(animation)

Tool.Equipped:Connect(function()
	animationTrack:Play()
end)

Tool.Unequipped:Connect(function()
	animationTrack:Stop()
end)

It works! thank you so much i’ve been stuck on how to script animations this will surely help me in the long run i can just look in here and always remember how to do it THANK YOU

1 Like

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