How would I apply an animation to a player while they are holding a tool

Hello everyone. I have made an animation with a dummy holding a tool, and I am not sure how to make this animation play and stay in the position the animation ended at while a player holds this tool. I am new to scripting and don’t know a lot about it, so I might get confused easily. Thanks for reading.

5 Likes

You would use the event Activated, and when it is, play the animation by using :Play(). This would be a script in the tool and the animation is a child of the script

2 Likes

So what you are saying is that I would have a script detect when the player is holding a tool and when that is detected run play to start the animation?

1 Like

All you have to do something like

      ''''
            local Animation = script.Parent.Animation -- insert animation id in the properties
            local hum = script.Parent.Parent.Humanoid -- The humanoid of the player
            script.Parent.Activated:Connect(function() -- When the tool is clicked
                   hum:LoadAnimation(Animation) -- Loads the animation
                   Animation:Play() -- Plays the animation
            end)

             '''

Tell me if it is not working

So would the animation be the two key frames in the Animation saves on the dummy or the untitled animation clip? Sorry I keep asking questions that probably have obvious answers. I’m just new to scripting and don’t know much about it.

Which animation plugin did you use?

I just used the one that was on there by default. It just has three options Rig builder, Avatar, and Animations.

Yeah so first import your animation, then right click on it, and click save to roblox and then it will load to roblox and then copy the numbers on the animation link, and paste it onto the animation id property. If you have more questions, feel free to ask

1 Like

What object would have the animation id property?

Do you have explorer and properties tap open? If not go to view and look to the left side and you will see both of them, once you done that, you click on the animation, and AnimationId property is the first one. Then insert my code into the script. (script should be a child of the tool, and the animation is a child of the script)

Yes. I do have these tabs open. I just can’t find the property where the ID goes.

Look at my post above (30 chars)

I think I just don’t know which object is the animation. Would it look like this? LocalScript - Roblox Studio 6_23_2020 10_06_05 AM

So right click on the square thing and click import to roblox, then copy the number on the animation link, and then post those number into a new animation, and put my code into the script

Would it be a local script or a script

A server script (30 charsssssss)

Ok. I get the error message Animation is not a valid member of tool. For line 1

          ''''
        local Animation = script.Parent.Animation -- insert animation id in the properties
        local hum = script.Parent.Parent.Parent.Humanoid -- The humanoid of the player
        script.Parent.Activated:Connect(function() -- When the tool is clicked
               hum:LoadAnimation(Animation) -- Loads the animation
               Animation:Play() -- Plays the animation
        end)

         '''
1 Like

You said the animation is a child of the script right?

yes it is (30 charsssssssssssss)