Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I code a sword without using Touched event?

Asked by 6 years ago

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

0
loop through the players and use magnitude if their in range User#23365 30 — 6y
0
Well.... That doesn't help... Danielkaya 58 — 6y
0
At least put the script on your question. Neon_N 104 — 6y
0
i should say the same, magnitude work pretty well. iagometroid 61 — 6y
View all comments (2 more)
0
What's wrong with what you have? Confused Shawnyg 4330 — 6y
0
use the idea i gave u to try replicate what u want to do User#23365 30 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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:

1function onTouched(hit)
2        local human = hit.Parent:findFirstChild("Humanoid")
3        if (human ~= nil) then
4                human.Health = human.Health - 50
5        end
6end
7script.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

01script.Parent.Equipped:connect(function()
02    script.Parent.Knife_Equip:Play()
03end)
04 
05 
06script.Parent.Activated:connect(function()
07    script.Parent.Blade["Damage Script"].Disabled = false
08    script.Parent.Knife_Slash:Play()
09    script.Parent.GripForward = Vector3.new(0,5,- 1)
10end)
11script.Parent.Deactivated:connect(function()
12    script.Parent.Blade["Damage Script"].Disabled = true
13    script.Parent.GripForward = Vector3.new(0,0,- 1)
14 
15end)

then insert another normal script into the tool and this script will be for welding so type in this:

01function 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.Part0,w.Part1 = last,v
10                    w.C0 = last.CFrame:inverse()
11                    w.C1 = v.CFrame:inverse()
12                    w.Parent = last
13                end
14                last = v
15                table.insert(parts,v)
View all 27 lines...

I hope this answer helped! :3

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Magnitude is how I code my melee weapons.

01cooldown = true
02range = 10
03damage = 25
04 
05plr1char = gmae.Workspace[plr1.Name]
06plr2char = game.Workspace[plr2.Name]
07 
08if ((plr1char.HumanoidRootPart.Position-plr2cha.HumanoidRootPart.Position).magnitude <= range) and cooldown then
09plr2char.Humanoid.Health = plr2char.Humanoid.Health < damage
10end

Obviously this isnt very efficient, but it should work.

Answer this question