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 5 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 — 5y
0
Well.... That doesn't help... Danielkaya 58 — 5y
0
At least put the script on your question. Neon_N 104 — 5y
0
i should say the same, magnitude work pretty well. iagometroid 61 — 5y
View all comments (2 more)
0
What's wrong with what you have? Confused Shawnyg 4330 — 5y
0
use the idea i gave u to try replicate what u want to do User#23365 30 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 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:

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

script.Parent.Equipped:connect(function()
    script.Parent.Knife_Equip:Play()
end)


script.Parent.Activated:connect(function()
    script.Parent.Blade["Damage Script"].Disabled = false
    script.Parent.Knife_Slash:Play()
    script.Parent.GripForward = Vector3.new(0,5,- 1)
end)
script.Parent.Deactivated:connect(function()
    script.Parent.Blade["Damage Script"].Disabled = true
    script.Parent.GripForward = Vector3.new(0,0,- 1)

end)

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

function weld()
    local parts,last = {}
    local function scan(parent)
        for _,v in pairs(parent:GetChildren()) do
            if (v:IsA("BasePart")) then
                if (last) then
                    local w = Instance.new("Weld")
                    w.Name = ("%s_Weld"):format(v.Name)
                    w.Part0,w.Part1 = last,v
                    w.C0 = last.CFrame:inverse()
                    w.C1 = v.CFrame:inverse()
                    w.Parent = last
                end
                last = v
                table.insert(parts,v)
            end
            scan(v)
        end
    end
    scan(script.Parent)
    for _,v in pairs(parts) do
        v.Anchored = false
    end
end

weld()
script:Remove()

I hope this answer helped! :3

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

Magnitude is how I code my melee weapons.

cooldown = true
range = 10
damage = 25

plr1char = gmae.Workspace[plr1.Name]
plr2char = game.Workspace[plr2.Name]

if ((plr1char.HumanoidRootPart.Position-plr2cha.HumanoidRootPart.Position).magnitude <= range) and cooldown then
plr2char.Humanoid.Health = plr2char.Humanoid.Health < damage
end

Obviously this isnt very efficient, but it should work.

Answer this question