Welcome everyone to this Tutorial!
What are we gonna do today? Let me tell you.
So you know the game Murder Mystery 2 right? There are tons of copies of it, but that one is the original. Today, I’m going to show you how to make a simple knife that can kill and it comes with a super fancy animation too! Ready? Let’s get started!
This tutorial will cover the:
- Animations
- And the actual script.
Oh also:
0. The knife itself
Almost forgot about this lol.
But this is super easy to do. Just open the toolbox and throw in a knife mesh (You should look at the meshes category). Obviously check if it has any scripts with bad intentions, and if you find any, Delete them. Then insert a tool object and put the knife handle in it.
Also add a hitbox to your knife. This is the zone where the knife will actually kill people.
All you gotta do, is just insert a part, resize it to the size of the knife (Or you could make it bigger ), and weld it to the knife itself. You just have to insert a WeldConstraint to the hitbox, set the part0 to the hitbox part, and the part1 will be the knife.
You can test this out by putting the tool in starterpack and playing the game. If your character suddently teleports somewhere, then you might have forgotten to unanchor the hitbox.
1. Animation
So much typing
Anyway, now it’s time for the animation! For this, I’m going to use the basic Roblox Animation
Editor Plugin, since everyone has it.
So, insert a dummy (Block or mesh rig is the best), turn on the plugin, then select a dummy.
Now, you’ll be prompted with a window asking you to name your animation something.
I don’t care what you name it to be honest.
And now, the animation. It shouldn’t be a really complicated animation, Just move the hand like it’s stabbing. It should be around 1 - 1,5 seconds long.
When you’re done, click on the 3 dots on the top of the plugin window, and it should show a list. at the top, you see a save button. Click it. Then you can publ-
WAIT
This is a really important thing when you make this animation, the Priority
At the bottom of the list, there’s the Animation Priority setting. Set it to Action.
If you don’t do this, the whole thing won’t work. The point is, don’t leave it on Core.
If you want to know why, check the comments.
Now, you can publish the animation to Roblox. If you want to make changes, just publish the animation, but before you click that bright blue button, there’s an option at the down left corner to update an already existing asset. Then select your animation. Boom.
2. Scripting
Here we go, the technical part.
Insert a Localscript into the handle, and delete the print line.
first, define the variables:
local Handle = script.Parent
local Tool = Handle.Parent
Next, the actual code. This is easier than you might think. All you gotta do, is just have a
local boolean set in the script, and when the tool is activated (Basically when the player clicks when the tool is equipped) then just set that boolean to true, and a few seconds later, just set it back to false.
local canKill = false
Tool.Activated:Connect(function()
if not canKill then
canKill = true
wait(1)
canKill = false
end
end)
Now, make a touched Event, so if the tool is touched, then just kill/damage the player.
Handle.Touched:Connect(function(hit)
if canKill then
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health -= 110
end
end
end)
Now if you try it, then… well… nothing happens?
How about you spam click and move continuously?
Ah yes, the dummy is now killed. But why didn’t it work first time?
Thats because the touchedEvent fires everytime the target part collides with anything else. Basically the TouchedEvent might not have the canKill set to true. You can check it by setting the waittime into a bigger number in the activated function. Works now? Good.
This is how we solve the Touched Problem:
Remember the animation you’ve made?
Create an animation object, and paste the animation’s ID inside the animationID, then Put it into the handle. We will do a LoadAnimation() function to make the character play the animation.
However, how do we know who’s the tool’s parent?
Just add an equipped function and some other variables:
local Animation = Handle["Slash1"] -- obviously change this to your Animation name.
local plr = nil
Tool.Equipped:Connect(function()
plr = Tool.Parent
end)
And finally, before the wait() in the Activated function, add this line:
local anim = plr.Humanoid.Animator:LoadAnimation(Animation)
anim:Play()
Test time!
The animation should play. If not, check the Output for any info. If there’s a big red text, then you’ve just got slapped with an error. Maybe you’ve made a spelling mistake, if so, correct it.
But after a while, it should look like this:
I really hope the video loaded
Anyway, the knife will play the slash animation, and it will actually damage people!
I really hope this tutorial was helpful, because OH MY GOD SO MUCH TYPING AHHHHHH
Bye.