I have a script to make my character do a animation when i click with the mouse button but it does the animation only when im walking or jumping, and not by clicking with the mouse.
ps: this is a local script in the StarterPack
01 | local player = script.Parent.Parent |
02 | local mouse = player:GetMouse() |
03 | local sword = player.PlayerGui.UI.Armor.Sword.ItemClass |
04 | local A = Instance.new( "Animation" ) |
05 | A.AnimationId = "http://www.roblox.com/Asset?ID=182377268" |
06 | local B = Instance.new( "Animation" ) |
07 | B.AnimationId = "http://www.roblox.com/Asset?ID=182377825" |
08 |
09 | mouse.KeyDown:connect( function (key) |
10 | if sword.Value = = "Sword" then |
11 | local animTrack = player.Character.Humanoid:LoadAnimation(A) |
12 | animTrack:Play() |
13 | elseif sword.Value = = "Axe" then |
14 | local animTrack = player.Character.Humanoid:LoadAnimation(B) |
15 | animTrack:Play() |
16 | end |
17 | end ) |
You should use Button1Down not KeyDown. KeyDown is used for keyboard keys like : WASD. Button1Down is when you left click. Also you should have the script wait before the player loads, you might have problems in online mode without it.
http://wiki.roblox.com/index.php?title=API:Class/Mouse/Button1Down
http://wiki.roblox.com/index.php?title=API:Class/Mouse/KeyDown
01 | repeat wait() |
02 | player = game.Players.LocalPlayer; |
03 | until (player) and (player.Character) |
04 |
05 | local mouse = player:GetMouse(); |
06 | local sword = player.PlayerGui.UI.Armor.Sword.ItemClass; |
07 | local A, B = Instance.new( "Animation" ), Instance.new( "Animation" ); |
08 | A.AnimationId = "http://www.roblox.com/asset/?id=182377268" ; |
09 | B.AnimationId = "http://www.roblox.com/asset/?id=182377825" ; |
10 |
11 | mouse.Button 1 Down:connect( function () |
12 | if sword.Value = = "Sword" then |
13 | local animTrack = player.Character.Humanoid:LoadAnimation(A); |
14 | animTrack:Play(); |
15 | elseif sword.Value = = "Axe" then |
16 | local animTrack = player.Character.Humanoid:LoadAnimation(B); |
17 | animTrack:Play(); |
18 | end |
19 | end ) |
Don't forget to mark this as solved and as the correct answer!