How to animate Tool Handles easily! [OLD POST]

Also, to add a cooldown, make a debounce. At the very top of the Script that you load your animations in, make a variable called “debounce”. here’s an example of what it should look like.

local debounce = false

Then inside of your script, under the Activated function, put this at the top of the script. I’ll paste it here so you don’t write something incorrectly.

local debounce = false

script.Parent.Equipped:Connect(function()
	
	IdleRest = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(game.ServerStorage.Animation)
	SwingAnimation = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(game.ServerStorage.SwingAnimation)


	IdleRest:Play()
-- Do not play the Swings animation here. You put that in the Activated function.
end)

script.Parent.Unequipped:Connect(function()
IdleRest:Stop()
SwingAnimation:Stop()
end)

-- THIS IS WHERE YOU ADD YOUR COOLDOWN!

script.Parent.Activated:Connect(function()
if not debounce then
   debounce = true
   SwingAnimation:Play()

   wait(3) -- Change this to the desired time until you can swing it again
   debounce = false
end
   
end)
3 Likes

I hope this helps. Do let me know of any future issues.

2 Likes

Thanks, it all works. Hope you make more tutorials in the future.

I certainly will do my best to make more tutorials in the future. If you have any ideas, please let me know, and stay safe.

2 Likes

Adding onto this, if you don’t want to have the full-body animate, and you just want the idle animation to have the weapon in the right place (or you want the knife to work with an animation pack you’ve already made and don’t want to remake it), simply create an animation, with the only keyframe being the handle. Adjust the keyframe how you’d like, and follow the script that was given and it should work.

Great tutorial, it’s helped me a lot.

4 Likes

This is a really good fix, and kinda flew by me ngl. Glad you got it here in time! Not many have seen this yet, but still quite a few. Please use this method if you don’t want the issue with your Core Animations and such.

3 Likes

I got a question, how do you make it so I can do, lets say, 2 swings instead of only 1 swing?

It depends on what you’re trying to achieve. If your trying to make it so when you click it plays an animation, then another, or when you click it plays an animation, then after you click again the animation is different.

I’d have to look into this a little more, but when I do figure it out I’ll let you know.

1 Like

Yes, that concept. I would like to see it and use it if it’s ok with you?

Edit: Like, just a test place for me to try it out ofcourse.

1 Like

If you’re going to, just make sure to give out the script because I don’t think you can just ask someone for the script on the developer forum so yeah this is a tutorial page so anything regarding should be released for learning purposes. I recommend you also get into scripting a bit more so you don’t run into these issues. Tons of great tutorials out there. Some good youtubers would be:

  • TheDevKing (awesome guy, learning from him primarily)
  • AlvinBlox (not all that straight forward IMO, but still has really good tutorials)
  • Sheasu (he made a beginner introduction video that got me into scripting, it was severely helpful.
3 Likes

It’s not that I don’t know how to script, it’s just that the concept of putting the “Stuff” together in a script thats hard. I know my variables, functions etc, just don’t know how to do it, no one explains it, they just go you do this, that so on.

Makes sense. I wasn’t saying you knew absolutely nothing, I was just saying those guys can help you learn better, so you can learn how to put the things together. There will be gaps when it comes to scripting and you’ll have to stitch it together :+1:

2 Likes

Thanks, Ima look on the internet for some more information.

Those YouTubers I listed will assist with patching the gaps further. I sure don’t know everything, I find myself not knowing how to do something, but then pulling what I know, experimenting, and I eventually get to a solid product. That’s basically how I pulled this whole tutorial together :slight_smile:

Edit: I’ll update this tutorial in the future with other customizable things with a separate post, that uses a variety of different scripts when possible.

2 Likes

That works too, but I might as well just extend this tutorial with the excess features that you can do with it regardless. Thanks though! I’ll exclude your part from it so there isn’t a duped tutorial.

2 Likes

Do what you may, not stopping you from doing anything. If it’s more easier, I can just put the script you put here in the extended tutorial, and credit you.

2 Likes

What if I wan’t the weapon to be connect to the left arm instead of the right arm? I did everything you said, but with the left arm. It seemed to work at first, but when I wanted to test it, it didn’t work, I even changed some code in the Motor6DHandler to LeftArm instead of RightArm and so on. Can you help me on this?

I believe the Tool has to be Welded/Motor6D’d to the Right Arm (or RightHand) at all times. I’m going to test this one right now, and see if I run into any issues. If it works with the Right Arm (or RightHand) and it doesn’t with the left, then it’s probably because of this reason.

2 Likes

Ok, thanks. You deserve a follow tbh.

1 Like

I think I have found what you have done wrong here.

Tools are automatically attached to the Right Arm at all times.

RightArmGrip = script.Parent["Right Arm"]:WaitForChild("RightGrip")

Remember this line of code? Do not edit this line, but edit the rest that say “Right Arm”

Fixed Code (from my knowledge)
-- You want to reference the BoolValue, the Motor6D, AND the name of your tool.

Tool = script.Parent:WaitForChild("Snow Bat")
MotorCheck = script.MotorCheck
Motor6D = script.Motor6D

--[[
Then you want to call a function so when you equip the tool, this script
will activate, and set the Motor6D's Part0, and Part1 to their respective
parts
]]

Tool.Equipped:Connect(function()
	Motor6D.Part0 = script.Parent:WaitForChild("Left Arm")
	Motor6D.Part1 = Tool:WaitForChild("Handle")

--[[
Since the 2 lines of code above do not run more than once when you equip
the tool for some reason, you want to put an if statement to check to see if the Bool was set to true
which has been done at the END of the equipped function
]]

	if MotorCheck == true then
		Motor6D.Part0 = script.Parent:WaitForChild("Left Arm")
		Motor6D.Part1 = Tool:WaitForChild("Handle")
	end

--[[
Unfortunately for us, Roblox Tools like to create a weld automatically to the Right Arm
EVERYTIME you equip the tool, and that can stop the Motor6D from doing it's work.
So below, we wait for the RightGrip to be added, then delete it. Easy peasy!
]]

	RightArmGrip = script.Parent["Right Arm"]:WaitForChild("RightGrip")
	wait()
	RightArmGrip:Destroy()

	MotorCheck = true
end)

--[[
This part of the script can be very crucial, or else the Motor6D might break.
When you unequip the tool, the Part0 and Part1 values are set to nil (nothing) to prevent
the Motor6D from breaking on next equip.
]]

Tool.Unequipped:Connect(function()
	Motor6D.Part1 = nil
	Motor6D.Part0 = nil
end)

-- And that is all for the script! --

p.s Make sure to change the name at the top of the script with your tool!

Also also…

You will have to go and reanimate the Tool so it has the Keyframes for the Left Arm instead of the Right Arm. I went and did that for the attack animation, but I didn’t for the idle, and that is why it’s in my left arm at the center.

3 Likes