Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a animation play from a tool?

Asked by
Nozazxe 107
3 years ago
Edited 3 years ago

I know how to do it, but it just loops even when I unequip the tool. I have a animation in my tool that I made, and I have a script in it that says

local tool = script.Parent
local toolanim = tool.Animation

tool.Activated:Connect(function()
local char = tool.Parent
local hum = char.Humanoid

local AnimationTrack = hum:LoadAnimation(toolanim)
AnimationTrack:play()
end)

1 answer

Log in to vote
2
Answered by 3 years ago

Hello.

The reason as to why your animation is looping is either, you set the wrong animation priority, or, you haven't told it to stop the animation when you unqeuipped your tool. This is very simple to do with the .Unequipped function. This function will call anytime the tool is unequipped. From there, we can tell the tool to stop the animation. I also reccomend to Load the animation before you activate the tool, and also use the Humanoid.Animator instead of just the humanoid, as that is deprecated.

Here is an example with your script:

local Tool = script.Parent
local ToolAnimation = Tool.Animation

local Character = Tool.Parent 
local Humanoid = Character.Humanoid

local Animation = Humanoid.Animator:LoadAnimation(ToolAnimation)

Tool.Activated:Connect(function()
    Animation:Play()
end)

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

Hope this helps!

0
Thanks Mate! Nozazxe 107 — 3y
Ad

Answer this question