I'm making a railgun that has custom animations, one for holding it normally and one for firing it. I am not good at playing animations are anything related to it, so it's probably gonna look really stupid, so sorry about that!
local tool = script.Parent local UserInputService = game:GetService("UserInputService") tool.Equipped:Connect(function() script.Hold:Play() end) tool.Unequipped:Connect(function() script.Hold:Stop() end) UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then script.Fire:Play() end end)
Thank you if you can help.
Animation
object does not have a Play
method. You need to load it into the Humanoid
so you can call the LoadAnimation
method of the Humanoid
object. When this method is called, and the Animation
argument is provided, it will create a new Instance
, an AnimationTrack
. This has a Play
method.-- LocalScript local tool = script.Parent tool.Equipped:Connect(function(mouse) wait() track = tool.Parent.Humanoid:LoadAnimation(tool.Hold) mouse.Button1Down:Connect(function() track:Play() end) end) tool.Unequipped:Connect(function() --No mouse parameter here! Common mistake to add it. track:Stop() end)
Stop
method of the AnimationTrack
to end said animation respectively.Common mistakes:
1: Your animation is an R6 animation. R6 animations won't work on R15 and R15 animations won't work on R6.
2: Your animation is blocked by the RightGrip
weld. The RightGrip weld in right hand stops the animations without some special things from playing.
The third and fourth one seems to be like the one you're in.
3: You didn't even load the animation to the humanoid. To do this, you need to index the Humanoid and do.
Humanoid:LoadAnimation(script.Hold)
Unloaded animations will not work.
4: Animations should be played from LocalScript. Animations that are played by LocalScripts are better and they'll still be shown to everyone on the server even on FE.
5: Animations should be loaded immediately once the tool is equipped.
Hopefully, this can help!