Displaying custom made animations for a tool?

So I’m building a game, and I’m going to have two basic weapons: a Hammer and a Spear. I’m making the spear first. I’ve already made an animation for holding it, and for stabbing, but I just have one issue: I’m not a good scripter, so I don’t know how to script the animations to play.

How can I make these animations play when I want them to?

I’ll try this, will say if it doesn’t work

1 Like

Use the script above and just change this line:

For this:

track = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(Anim)

Okay, I’ll change that and see the results.

Wait, I just realized I don’t know how to define which animation the script will play.

Animations have AnimationIds, which is how you know which one its going to play, so something like this,

local HammerAnim = Instance.new("Animation")
HammerAnim.AnimationId = "yourid"
local SpearAnim = Instance.new("Animation")
SpearAnim.AnimationId = "yourid2"

local HammerTrack = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(HammerAnim)
local SpearTrack = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(SpearAnim)

This is basically how you could set up both animations then when you activate a tool you could do

yourtool.Activated:Connect(function()
HammerTrack:Play()
-- other code
end)

yourtool2.Activated:Connect(function()
SpearTrack:Play()
-- other code
end)

I think you can also just directly put animations into the character with set Ids and call those.

2 Likes

Copy the numbers and then put them at the end of the text.

image

AnimationId = "rbxassetid://123456789"
1 Like

Ohhh, thanks. That helps me a lot. Will do that and see if it works.

Your solution worked, thank you!