Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make a animation play from a tool?

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

✓ Accepted answer

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!

1 comment

0

Thanks Mate!

This discussion is preserved as it was. New answers, comments, and votes are closed.