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
local player = script.Parent.Parent local mouse = player:GetMouse() local sword = player.PlayerGui.UI.Armor.Sword.ItemClass local A = Instance.new("Animation") A.AnimationId = "http://www.roblox.com/Asset?ID=182377268" local B = Instance.new("Animation") B.AnimationId = "http://www.roblox.com/Asset?ID=182377825" mouse.KeyDown:connect(function(key) if sword.Value == "Sword" then local animTrack = player.Character.Humanoid:LoadAnimation(A) animTrack:Play() elseif sword.Value == "Axe" then local animTrack = player.Character.Humanoid:LoadAnimation(B) animTrack:Play() end 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
repeat wait() player = game.Players.LocalPlayer; until (player) and (player.Character) local mouse = player:GetMouse(); local sword = player.PlayerGui.UI.Armor.Sword.ItemClass; local A, B = Instance.new("Animation"), Instance.new("Animation"); A.AnimationId = "http://www.roblox.com/asset/?id=182377268"; B.AnimationId = "http://www.roblox.com/asset/?id=182377825"; mouse.Button1Down:connect(function() if sword.Value == "Sword" then local animTrack = player.Character.Humanoid:LoadAnimation(A); animTrack:Play(); elseif sword.Value == "Axe" then local animTrack = player.Character.Humanoid:LoadAnimation(B); animTrack:Play(); end end)
Don't forget to mark this as solved and as the correct answer!