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

How do I make Swords only deal damage on a certain part or parts?

Asked by 10 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

Like for example in Fencing how the foil's only deal damage to the people on the black plates. How would you script that into a sword to where it can only do damage on a certain part or brick.

2 answers

Log in to vote
1
Answered by 10 years ago

Well, you would want to detect which part you were hitting, so i'd do something like:

local Obj = script.Parent
local Targets = {
["TargetNameHere"] = true;
}
Obj.Touched:connect(function(Hit)
    if Hit.Parent:findFirstChild("Humanoid") and Targets[Hit.Name] then
        Hit.Parent.Humanoid:TakeDamage(15)
    end
end)

As you can see, I checked to see if the name of the part hit was in the table of names, and only after that was verified did the damage take effect. In this case the weapon (eg. sword) was the script's parent (Obj).

Ad
Log in to vote
0
Answered by 10 years ago

What I would do, is the name damageable part "hittarget", and in the sword's script, i'd add an "if" condition, which would check whether the part it hit is named "hittarget", and only then would it deal damage.

Answer this question