So here's the thing, I created a sword and a simple script which deduct health when an enemy touched the sword blade using ('Debounce' so it won't take health multiple times) . It works like a charm , but if I created a sword combo attack. The sword must go through the enemies body multiple times. How do I do this so it take damage each time the sword hit an enemy?
I tried Raycast , but ray ain't efficient (I guess)
This srsly sound like a request , I just need some tips , idea , or maybe advice to make a sword capable of doing combo.
Thanks :D
I have got a super easy way to code swords and it doesnt take much effort
so step number 1 is to insert a on touch damage script into the blade. The script should look lie this:
1 | function onTouched(hit) |
2 | local human = hit.Parent:findFirstChild( "Humanoid" ) |
3 | if (human ~ = nil ) then |
4 | human.Health = human.Health - 50 |
5 | end |
6 | end |
7 | script.Parent.Touched:connect(onTouched) |
and set the script to disabled
now,you want to insert 2 sounds into the tool, a equip sound and a knife slash sound. then just insert a normal script into the tool and type in this
01 | script.Parent.Equipped:connect( function () |
02 | script.Parent.Knife_Equip:Play() |
03 | end ) |
04 |
05 |
06 | script.Parent.Activated:connect( function () |
07 | script.Parent.Blade [ "Damage Script" ] .Disabled = false |
08 | script.Parent.Knife_Slash:Play() |
09 | script.Parent.GripForward = Vector 3. new( 0 , 5 ,- 1 ) |
10 | end ) |
11 | script.Parent.Deactivated:connect( function () |
12 | script.Parent.Blade [ "Damage Script" ] .Disabled = true |
13 | script.Parent.GripForward = Vector 3. new( 0 , 0 ,- 1 ) |
14 |
15 | end ) |
then insert another normal script into the tool and this script will be for welding so type in this:
01 | function weld() |
02 | local parts,last = { } |
03 | local function scan(parent) |
04 | for _,v in pairs (parent:GetChildren()) do |
05 | if (v:IsA( "BasePart" )) then |
06 | if (last) then |
07 | local w = Instance.new( "Weld" ) |
08 | w.Name = ( "%s_Weld" ):format(v.Name) |
09 | w.Part 0 ,w.Part 1 = last,v |
10 | w.C 0 = last.CFrame:inverse() |
11 | w.C 1 = v.CFrame:inverse() |
12 | w.Parent = last |
13 | end |
14 | last = v |
15 | table.insert(parts,v) |
I hope this answer helped! :3
Magnitude is how I code my melee weapons.
01 | cooldown = true |
02 | range = 10 |
03 | damage = 25 |
04 |
05 | plr 1 char = gmae.Workspace [ plr 1. Name ] |
06 | plr 2 char = game.Workspace [ plr 2. Name ] |
07 |
08 | if ((plr 1 char.HumanoidRootPart.Position-plr 2 cha.HumanoidRootPart.Position).magnitude < = range) and cooldown then |
09 | plr 2 char.Humanoid.Health = plr 2 char.Humanoid.Health < damage |
10 | end |
Obviously this isnt very efficient, but it should work.