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

How could I make it so an animation would play when a tool is equipped?

I've tried this,

handle = script.Parent.Handle

Weapon.Equipped:connect(function(mouse)
handle.idle:Play()

end)

This script works fine when playing a sound but I haven't been able to get it to work with animations.

2 comments

0

Has the animation got an ID? And are you giving the tool enough time to load the animation?

0

Use the humanoid:LoadAnimation(animation) function on the humanoid first.

1 answer

Animations are a bit different. You need to load animations into the Players Humanoid.

LocalScript:

repeat wait() until game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer
local anim = Player.Character.Humanoid:LoadAnimation(script.Animation)
local tool = script.Parent

tool.Equipped:connect(function()
	wait(0.5)
	anim:Play()
	wait(1.5)	
	anim:Stop()
end)

Please accept this answer if it solved your problem, thanks!

3 comments

0

That script does not work. It's because of the fact that the Repeat requires an Until for it to work.

0

Oops, my bad, must've forgot that. Kind of wrote it in a haste.

0

That's alright, I kinda sorta figured it out.

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