Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this gun animate in R15?

Asked by 5 years ago

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.

0
Edited it! User#19524 175 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

This is because the 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.

It’s bad practice to put your animation inside a script, put it in a folder inside the tool if there are lots of animations. Else, just put it in the tool.

-- 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)

This is just an example of how to properly play animations and load them. Use this script and do the same with your other animations. Use the Stop method of the AnimationTrack to end said animation respectively.

0
It works, but is there a way to make the animation stop when it is unequipped? I tried tool.unequipped, but it didn't work for me. CaptainAlien132 225 — 5y
Ad
Log in to vote
0
Answered by
SCP774 191
5 years ago
Edited 5 years ago

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!

1
Why do you assume it’s an R6 animation? Also stop copying me. User#19524 175 — 5y

Answer this question