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