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

How do I make a looped animation when holding a tool?

I've got this animation that I want to loop whenever I hold a certain tool, the animation should stop when I unequip the tool. So can someone tell me how I'd do that? (NOTE: I don't need an already existing script to be fixed, I just need someone to tell me how).

2 comments

0

you might need a script, what i can fix

2 answers

in the animation editor itself, making an animation that has a higher priority than Movement, also making it a loop.

How to loop

How to set priority

to play the animation, you must load it into the humanoid with local AnimTrack = Humanoid:LoadAnimation(Animation)

wiki page

and then play the track when tool is equipped AnimTrack:Play()

and stop when it's unequipped AnimTrack:Stop()

(i assume you already know how to use Tool.Equipped and Tool.Unequipped)

Tool.Equipped

Tool.Unequipped

You just set the animation to loop, once you've done that do the following:

  • Create a new Animation instance.
  • Put the animation in the game. (Somewhere like in your tool or ReplicatedStorage).
  • Put the AnimationId in the Animation Instance.
  • Make the animation a variable, preferably in a LocalScript.
  • Put this in the LocalScript (put the LocalScript in the Tool):
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Animation = game.ReplicatedStorage:WaitForChild('Animation')

local ToolAnim = Character:WaitForChild('Humanoid'):LoadAnimation(Animation)

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

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

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