In this tutorial, you will learn how to create a working and functional sword in Roblox Studio. Let’s debunk the steps on how to create one.
I know there are tutorials out there but I would like to create a simple tutorial on how to create one. I might be able to answer your questions/comments on the replies section of this post.
Making The Mesh/Sword Instance
It isn’t required to have blender but I would like to suggest having blender to create this part. Now, on blender, use the key combination Shift+A to create a new part. After that, make sure to select the corners of the object and configure their properties. You can extrude (e), scale (s), and rotate (r) the object corners. Once you’re done, export the object. Make sure to export the object as a .obj file.
Importing the Mesh
In Roblox, click the view tab in the upper part of your screen. Above the toolbox and to the right of Properties, you will find the asset manager. Click the button and a GUI will pop up in your screen. Click the box with a horizontal arrow pointing towards it and import your .obj file.
Making the Tool Instance
Name your mesh (or union) handle. This will make it so you can hold the tool. After that, add a script inside your tool. You may call your script anything, but in this screenshot I decided to name my script “Main”.
Creating the Animations
Click the “Avatar” tab in your studio and click “Rig Builder”. I would suggest R6 but you may use any rig type. The image shows what my rig would look like.
Once you created your rig, select it and click “Animation Editor”. Use the “Move” and “Rotate” actions found in your “Model” or “Home”. You may select any keyframe or point in your animation to configure it.
Make sure you publish your animation and copy the animation id given to you once you publish your animation.
Create a new animation in your script instance and name it “Slay”. After that, add your animation id in your animation instance.
Note: Make sure to set the animation priority found in the three dots in the corner to idle so the animation will play with the sword.
Scripting the sword
The script you would put in is this:
script.Parent.Equipped:Connect(function()
if script.Parent.Parent.Humanoid.RigType == Enum.RigType.R15 then
script.Parent:Destroy()
end
script.Parent.Activated:Connect(function()
hitable = true
if script.Parent.Parent.Humanoid.Animator == nil then
local animator = Instance.new("Animator", script.Parent.Parent.Humanoid)
end
script.Parent.Parent.Humanoid.Animator:LoadAnimation(script.Slay):Play()
wait(3)
hitable = false
end)
end)
script.Parent.Handle.Touched:Connect(function(opart)
if opart.Parent.Humanoid ~= nil then
if opart.Parent.Name ~= script.Parent.Parent.Name then -- So the sword won't damage the other player
if hitable == true then
hitable = false
opart.Parent.Humanoid.Health = opart.Parent.Humanoid.Health -35
end
end
end
end)
I will break it down for you guys.
When the tool is equipped, it will first make sure the RigType is R15. You might want to delete that if you have an R15 animation.
When the tool is activated, it will make a local bool value (hitable) true. This will also play an animation located in the script instance. After 3 seconds, the bool value (hitable) will be set to false.
When the handle is touched, the script will make sure that the player is not taking damage from it and if the character is a valid character. If the handle is touched by a valid character, the player will begin to take damage.
Conclusion
Enjoy your new sword! Just like I said in the beginning, please ask your questions/comments in the replies section and I will answer them for you whenever I can. Thanks for using this tutorial and hopefully, this tutorial helped!