ok so my animation is not playing when i equip a tool and i click, i want a animation to play, yet it isnt, any reason why?
01 | local Players = game:GetService( "Players" ) |
02 |
03 | script.Parent.Equipped:Connect( function (mouse) |
04 | mouse.Button 1 Down:Connect( function () |
05 |
06 | local Players = game:GetService( "Players" ) |
07 |
08 |
09 | local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation) |
10 | wait( 1.2 ) |
11 | animation:Play() |
12 |
13 | end ) |
14 | end ) |
Why are you waiting for wait(1.2)?
Just play the animation right after:
01 | local Players = game:GetService( "Players" ) |
02 |
03 | local animation = game.Players.LocalPlayer:WaitForChild( "Character" ):WaitForChild( "Humanoid" ):LoadAnimation(script.Parent.Animation) |
04 |
05 | script.Parent.Equipped:Connect( function (mouse) |
06 | mouse.Button 1 Down:Connect( function () |
07 |
08 | local Players = game:GetService( "Players" ) |
09 |
10 |
11 | animation:Play() |
12 | end ) |
13 | end ) |
Also make your animation priority in the editor to action: other action animations will still override this, so its safe to set equip (and other things) animations to action
EDIT: i fixed so it waits for the humanoid
****Try changing
1 | game.Players.LocalPlayer.Character.Humanoid |
to this
1 | game.Players.LocalPlayer.Character:WaitForChild( "Humanoid" ) |
****Update
Your problem may be the fact that this script is running before your character has loaded.
So, you would do something like this :
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character or player.CharacterAdded:Wait() |
03 | local hum = char:WaitForChild( 'Humanoid' ) |
04 |
05 | local animation = hum:LoadAnimation(script.Parent.Animation) |
06 |
07 | script.Parent.Equipped:Connect( function (mouse) |
08 |
09 | mouse.Button 1 Down:Connect( function () |
10 | wait( 1.2 ) |
11 | animation:Play() |
12 | end ) |
13 |
14 | end ) |
thanks for your help everyone i finally found out the reason why it wasnt working, i was in r15, the animation was for only r6, thank you to those who helped!