local tool = script.Parent local player = game:GetService("Players").LocalPlayer tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() script.Parent.LeftSlash:Play() end) end)
Error
15:09:49.404 - Play is not a valid member of Animation
15:09:49.405 - Script 'Players.Player1.Backpack.Knife.LocalScript', Line 21
15:09:49.406 - Stack End
I want it so when the player clicks it plays this animation but it doesnt work. Please help.
You have to load the animation into the humanoid:
local tool = script.Parent local player = game:GetService("Players").LocalPlayer hum=player.Character:WaitForChild("Humanoid") tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local animTrack = hum:LoadAnimation( script.Parent.LeftSlash) animTrack:Play() end) end)
Well, you have to play the animation inside of the humanoid, not the tool. Therefore, I suggest putting the animation inside of ServerStorage (or if you don't prefer that, you could go the classic way and use Lighting) . First, set the variables:
local animation = game.Lighting.LeftSlash:Clone() --[[ This clones the animation so that it does not directly move the one inside ServerStorage and load it into the humanoid, allowing for it to be used multiple times.]] local LoadAnimation = player.Character.Humanoid:LoadAnimation(animation) --[[ This loads the animation into the humanoid, but does not play it.]] LoadAnimation:Play() --[[This plays the loaded animation. To stop it you would do LoadAnimation:Stop() as long as it's inside the same area where the animation was ran.]]
That leaves us with this:
local tool = script.Parent local player = game:GetService("Players").LocalPlayer tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local animation = game.Lighting.Whip:Clone() local LoadAnimation = player.Character.Humanoid:LoadAnimation(animation) LoadAnimation:Play() --If you want to stop it within a certain amount of time wait(3) LoadAnimation:Stop() end) end)
If anything doesn't work, comment what the error is and I'll see if I can fix it. I'm not the best with animations but I believe this should work.