How to make a Simple Sword Tutorial

Simple Sword Tutorial

Hello guys,

Today we will start by making our own Sword.

Firstly, we need to make a sword model in Roblox Studio and then union it.
If you have made it from blender you can export it as fbx and after you import it in Roblox Studio weld all the parts using f3x.
When you are done add a tool in the workspace and drag your sword model there.
Also, you can add it to the starterpack so, when the player joins the game the tool is inside his inventory.
image
Now, you can adjust the grip position or the orientation using the toolgrip plugin or my method in my YouTube video

Now, that we have finished with the model let’s move to the scripting part!
First insert a script inside the union that we made
image

We want to make it so something happens everytime the sword is touched to do that we will use the “Touched” Event and connect it to a function. (To learn more
about functions click here)

Here is how it should be like:

script.Parent.Touched:Connect(function()

end)

To make changes to the part that touched it we can type something inside the parenthesis
image
As you can see I have named it hit you can name it however you want.
“hit” is the part that has touched the sword and as I said it doesn’t have to be named like that

Now, that we are done with this part too we need to find the character model of the player

script.Parent.Touched:Connect(function(hit)
local Character = hit.Parent
end)

When the sword is touched and the player was the one who touched it (every part can touch it not only the player) then a child of the player touched it not the whole model
image
Here when I touched the part the LeftLowerArm touched it which is a child of the model.
So, to make changes to the model of the player we can say hit.Parent.
And now we can decrease the health of the player.

script.Parent.Touched:Connect(function(hit)
local Character = hit.Parent
Character.Humanoid.Health = Character.Humanoid.Health - 10 --The damage
end)

So, Humanoid is in every character of a player and it is used to change some of it’s properties (walkspeed, health, jumppower etc.) so that’s why we said Character.Humanoid
But, if a part touches the sword which is not a player and it doesn’t have humanoid in it errors will pop up so, to solve that we can decrease the damage only if the parent of the part that touched it has humanoid in it.

script.Parent.Touched:Connect(function(hit)
local Character = hit.Parent
if Character:FindFirstChild("Humanoid") then
Character.Humanoid.Health = Character.Humanoid.Health - 10 --The damage
end
end)

We can also decrease the damage and add a wait so the player doesn’t die instantly

script.Parent.Touched:Connect(function(hit)
task.wait(0.3)
local Character = hit.Parent
if Character:FindFirstChild("Humanoid") then
Character.Humanoid.Health = Character.Humanoid.Health - 5 --The damage
end
end)

Congratulations! You made your first working Sword make sure to check my channel too for more tutorials. https://www.youtube.com/channel/UC3AJwDsGVwSf5cgAvS9m8NA

4 Likes